Skip to content
Open
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
are removed.

### Performance
- **Parser**: function arguments, the SELECT list, GROUP BY and ORDER BY are now collected on parser-owned scratch stacks and copied once into exact-size slices (previously grown with `append` from a fixed capacity). A `FunctionCall` with up to three arguments shares one allocation with its argument array, and a `SelectStatement` shares one with its single `From` entry and, for up to four columns, its `Columns` array. Parse allocations drop 28% on `aggregate` (18 to 13) and 12% on `complex` (50 to 44), and instructions per parse drop 1-5% on every SELECT shape. Time on the amd64 CI gate (five runs on three runner CPU models): `simple_select` 4-5% faster, `subquery` 3-6% faster; the other SELECT shapes vary by runner from about 4% faster to 4% slower. INSERT, UPDATE and DELETE execute the same instructions as before but measured up to 5% slower on AMD Zen 5 runners (`insert` +5% in two of three runs, and the mixed `ParseRW/sqlite/medium` corpus up to +5%), and within 2% on the other runner CPUs. Zero-instruction-change controls (only padding `Parser` or only moving code in the binary) moved single benchmarks by +3.4% to -4.5% on the same gate, so these are most likely code and data placement effects rather than added work. User-visible: `Columns`, `GroupBy`, `OrderBy` and `FunctionCall.Arguments` now have `len == cap` (they used to carry spare capacity), so a caller that appends to them reallocates instead of writing into spare space; trees are otherwise identical (guarded by the behaviour goldens). No exported API change. [W4-04]
- **`ast.ReleaseAST` is O(1) for parser-built trees that hold no pooled nodes**: the parser counts the nodes it draws from the AST pools and tells
`ReleaseAST` through an internal hook (`pkg/sql/internal/astrelease`). When
the count is zero, which covers ordinary SELECT/INSERT/UPDATE/DELETE
Expand Down
28 changes: 14 additions & 14 deletions pkg/gosqlx/alloc_budget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ import (

// parseAllocBudget is allocs/op of Parse+ReleaseAST for the 11 portable queries.
var parseAllocBudget = map[string]float64{
"simple_select": 5,
"select_where": 18,
"join": 17,
"aggregate": 18,
"subquery": 14,
"cte": 21,
"window": 11,
"complex": 50,
"simple_select": 3,
"select_where": 16,
"join": 15,
"aggregate": 13,
"subquery": 10,
"cte": 16,
"window": 9,
"complex": 44,
"insert": 17,
"update": 13,
"delete": 5,
Expand All @@ -69,14 +69,14 @@ var dialectAllocStatement = map[string]string{
// dialectAllocBudget is allocs/op of ParseWithDialect+ReleaseAST for the
// statement pinned in dialectAllocStatement.
var dialectAllocBudget = map[string]float64{
"postgresql": 37,
"postgresql": 29,
"mysql": 50,
"mariadb": 61,
"sqlserver": 36,
"oracle": 68,
"sqlite": 48,
"snowflake": 71,
"clickhouse": 82,
"sqlserver": 28,
"oracle": 52,
"sqlite": 47,
"snowflake": 53,
"clickhouse": 80,
}

const allocRuns = 200
Expand Down
Loading
Loading