Skip to content

v0.6.6: per-parse list-building scratch buffers#83

Open
tamnd wants to merge 1 commit into
mainfrom
v0.6.6
Open

v0.6.6: per-parse list-building scratch buffers#83
tamnd wants to merge 1 commit into
mainfrom
v0.6.6

Conversation

@tamnd
Copy link
Copy Markdown
Owner

@tamnd tamnd commented Apr 28, 2026

Summary

  • parseStringAtom fast path: single plain string literals return directly from arenaAlloc — no plainParts []string allocation; multi-part strings reuse p.ar.plainPartsBuf
  • parseSimpleStmtList scratch buffer: var stmts []Stmt replaced by arena's simpleStmtBuf; callers consume via append(outer, ss...) before the next call; inline-block path copies out to protect AST correctness
  • Assignment target slab (exprLists): targets := []Expr{lhs} replaced by contiguous segments in a new p.ar.exprLists arena slab, reset per parse

Benchmark (Apple M4, 10 cores)

v0.6.5 v0.6.6 Δ
Serial MB/s 116.8 119.0 +2%
Parallel MB/s 400.6 419.4 +5%
B/op 64 MB 55 MB −14%
Allocs/op 2.0M 1.43M −29%

Test plan

  • go test ./... passes
  • CI corpus parse, roundtrip, astdiff, oracle all green
  • Fuzz pass green

Eliminates per-call heap allocations for three hot list-building patterns
identified by pprof in v0.6.5:

- parseStringAtom: single plain string literals now take an early return
  that skips the plainParts []string accumulator entirely; multi-part strings
  write into p.ar.plainPartsBuf (pre-grown, reused per parse).

- parseSimpleStmtList: var stmts []Stmt replaced by the arena scratch buffer
  p.ar.simpleStmtBuf; callers consume via append(outer, ss...) before the
  next call, satisfying the safety contract. The inline-block path copies out.

- parseExprBasedStmt: targets := []Expr{lhs} replaced by contiguous segments
  of p.ar.exprLists, a new slab field reset per parse alongside the node slabs.

Serial: +2% (116.8 → 119.0 MB/s). Parallel: +5% (400.6 → 419.4 MB/s).
Allocs/op: −29% (2.0M → 1.43M). B/op: −14% (64 MB → 55 MB).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant