[codex] Split parser single-branch path#376
Closed
adamziel wants to merge 1 commit intoexplore/lexing-parsing-10xfrom
Closed
[codex] Split parser single-branch path#376adamziel wants to merge 1 commit intoexplore/lexing-parsing-10xfrom
adamziel wants to merge 1 commit intoexplore/lexing-parsing-10xfrom
Conversation
Collaborator
Author
|
Closing per request; scrapping this parser rearchitecture experiment. |
5 tasks
JanJakes
added a commit
that referenced
this pull request
Apr 28, 2026
`! empty( $this->children )` short-circuits without calling `count()`, saving one function call per invocation. Co-authored-by: Adam Zieliński <adam@adamziel.com> Adapted from #376
JanJakes
added a commit
that referenced
this pull request
Apr 28, 2026
`! empty( $this->children )` short-circuits without calling `count()`, saving one function call per invocation. Co-authored-by: Adam Zieliński <adam@adamziel.com> Adapted from #376
JanJakes
added a commit
that referenced
this pull request
Apr 29, 2026
`! empty( $this->children )` short-circuits without calling `count()`, saving one function call per invocation. Co-authored-by: Adam Zieliński <adam@adamziel.com> Adapted from #376
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.
What changed
This stacked draft PR builds on #375 and gives the parser a dedicated fast path for the common case where FIRST-set dispatch resolves a rule to exactly one candidate branch.
WP_Parser::parse_recursive().WP_Parser_Node::has_child()fromcount() > 0to! empty()for the hot AST completion check.Why
After #375, branch dispatch commonly resolves directly to a single branch. The parser still paid loop/index bookkeeping designed for multiple candidates. This change duplicates a small amount of branch parsing code so the dominant single-candidate path can avoid that work while keeping the generic parser architecture intact.
This is deliberately still compact: it does not generate a large parser or expand the grammar on disk.
Performance
Benchmarks are noisy on this machine, so I compared this branch against the stacked base branch immediately before opening this PR.
11.55021s@6,023 QPS10.90099s@6,382 QPSThat is roughly a
6%incremental parser improvement on top of #375 in this run.Parser size constraint
src/parser/*.phpplussrc/mysql/mysql-grammar.phpremains under the requested 200 KB on-disk cap:95,298bytes totalValidation
git diff --checkphp -lon modified parser filescomposer run test -- --filter 'WP_MySQL_(Lexer|Server_Suite_(Lexer|Parser))|WP_Parser_Node'143tests1,421,037assertionscomposer run test667tests1,427,673assertions2skipped,2incompletephp packages/mysql-on-sqlite/tests/tools/run-parser-benchmark.phpNotes
I also tested broader parser reshapes before settling on this smaller fast path: inline terminal matching, in-memory single-fragment expansion, lightweight fragment arrays, direct branch-array dispatch, and by-reference parser cursor state. Those were slower in this codebase, so they are not included here.