Skip to content

Allocate the AST in an arena - #2

Merged
TomasVotruba merged 4 commits into
mainfrom
arena
Dec 3, 2026
Merged

TomasVotruba merged 4 commits into
mainfrom
arena

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Builds the whole AST in a bump arena (bumpalo), the way mago-syntax does, to remove the malloc/free and drop cost that took ~43% of CPU time in a perf profile.

What changes

  • parse(&arena, source, config) - the caller owns an Arena; dropping it frees the tree at once
  • Node variants hold &'a mut T instead of Box<T>, lists are arena Vecs
  • Token is Copy: its value is a plain &[u8] and free-floating tokens are an arena slice
  • node structs become nodes with .node(arena) instead of .into()
  • Attributes hold strings only (the resolved name was the only user) and live in the arena
  • Formatter::new(&arena), NamespaceResolver::new(&arena), resolve_names(&arena, ..), Registry::collect(&arena, ..)

Same output

The dump stays byte-identical to the Go parser: Laravel at 8.4 and 7.4, Symfony at 8.4 and 7.4, a PHP 7.4-era Laravel at 7.4 and 5.6, and all fixtures.

Speed

Laravel (18157 files) on 4 cores in CI, average over 5 runs:

Parser Before After Peak mem
php-parser-in-rust 1186 ms 300 ms 96 MB (was 153 MB)
php-parser-in-go 1616 ms 4429 MB
mago-syntax 341 ms 145 MB

Benchmark workflow fix

The benchmark step piped into tee without pipefail, so it passed even when bench/compare.sh failed. That happened once the Rust cache restored a pruned Go checkout. The step now fails on errors and the script reclones the checkout.

@TomasVotruba
TomasVotruba merged commit ee5bf79 into main Dec 3, 2026
3 checks passed
@TomasVotruba
TomasVotruba deleted the arena branch December 3, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant