Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parseStringAtomfast path: single plain string literals return directly fromarenaAlloc— noplainParts []stringallocation; multi-part strings reusep.ar.plainPartsBufparseSimpleStmtListscratch buffer:var stmts []Stmtreplaced by arena'ssimpleStmtBuf; callers consume viaappend(outer, ss...)before the next call; inline-block path copies out to protect AST correctnessexprLists):targets := []Expr{lhs}replaced by contiguous segments in a newp.ar.exprListsarena slab, reset per parseBenchmark (Apple M4, 10 cores)
Test plan
go test ./...passes