You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Performance: array growth helpers zero-fill every new element; no unchecked-grow path #424
All array-growth helpers in the stdlib (exparr_grow, tokarr_grow, namearr_grow, coldefarr_grow, i32arr_grow, ...) realloc then value-initialize every new element — even when the caller immediately overwrites each element's fields. There is no way to grow without the zeroing pass, and no way to avoid the per-array initial allocation cost.
Impact (real workload)
flow-sqlite mints one Parser per SQL statement. new_parser() pre-allocates:
64 Token × 144 B = 9.2 KB
64 Expr × 832 B = 53 KB
of element initialization per statement, before a single token is read. Profiling the REPL's hot SELECT loop (sample, 3 s, Apple M1) showed ~35% of samples inside new_parser (57/161), dominated by exparr_grow's memset/memmove. After we switched the REPL to reuse one parser across statements (parser_reset keeping the pools warm), the cost moved to the per-statement statement arrays: namearr_grow still zeroes 16 × 128 B = 2 KB for a FROM list that uses 1 entry, and ~25% of samples sit in namearr_grow/selcolarr_grow/pair_i32_grow for tiny lists.
Two separate costs, both fixable:
Zero-fill on growth — p_new_expr assigns every field of Expr; the growth helper's per-slot initialization is pure waste. A grow_uninit(a, cap, need) (realloc without the element loop) would cut the 53 KB memset to zero for the common case.
Minimum-capacity allocations — helpers floor the initial capacity at 16 (nc < 16 → 16); a 1-entry NameBuf list allocates 2 KB. Callers who know the size upfront would prefer alloc_exact.
Suggested fix
Add an unchecked/uninitialized growth variant (e.g. grow_uninit) for callers who guarantee element initialization.
Reconsider the fixed 16 minimum — either alloc_exact for sized callers, or a smaller default (4) with geometric doubling.
Document the zero-fill contract on the existing helpers.
Activity
feat: uninitialized growth helpers and arena regression tests (#424, #…
fix: -O2 default, pointer address type check, regression tests (#428)
godofecht commentedon Aug 11, 2026
Fixed in PR #428 (merged).