[codex] Add native token stream parser fast path#380
Closed
adamziel wants to merge 1 commit intocodex/native-parser-fast-pathfrom
Closed
[codex] Add native token stream parser fast path#380adamziel wants to merge 1 commit intocodex/native-parser-fast-pathfrom
adamziel wants to merge 1 commit intocodex/native-parser-fast-pathfrom
Conversation
This was referenced Apr 28, 2026
8bffd34 to
dbf7072
Compare
5a9067a to
56c4280
Compare
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 stacks on #379.
WP_MySQL_Native_Token_Stream, a compact Rust token stream returned byWP_MySQL_Native_Lexer::native_token_stream().WP_MySQL_Native_Parserto accept either the existing PHP token array or the native token stream.Why
#379 made AST materialization faster, but the driver still created millions of PHP token objects before Rust parsing started. This branch lets Rust parse compact token metadata directly and only materialize PHP-compatible token objects when an AST is requested.
The stack-growth guard was also on the recursive hot path. Keeping the guard at the parse/materialization boundary preserves the stack-growth behavior while removing a large per-rule overhead.
Benchmark
Methodology:
next_query(), and callsget_query_ast()for every query.Validation
cargo fmt --checkcargo build --releasecomposer run check-csphp -d extension=/tmp/mysql-parser-perf/target-stream-release2/release/libwp_mysql_parser.so -d memory_limit=1024M ./vendor/bin/phpunit -c ./phpunit.xml.dist --filter 'MySQL|Parser|Lexer'php -d extension=/tmp/mysql-parser-perf/target-stream-release2/release/libwp_mysql_parser.so -d memory_limit=1024M ./vendor/bin/phpunit -c ./phpunit.xml.distphp -d memory_limit=1024M ./vendor/bin/phpunit -c ./phpunit.xml.dist --filter 'WP_PDO_MySQL_On_SQLite_PDO_API_Tests::test_query$'