Skip runs of horizontal whitespace in one scan in Lexer::positionAfte… - #1963
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the lexer’s whitespace skipping by consuming long runs of horizontal whitespace (tabs, spaces, commas) in a single native scan, while keeping the existing per-character handling for BOM and line terminators to preserve correct line/column tracking.
Changes:
- Added
Lexer::HORIZONTAL_WHITESPACE_BYTESand usedstrspn()inpositionAfterWhitespace()to bulk-skip horizontal whitespace. - Kept existing logic for BOM, LF, CR, and CRLF handling to maintain correct
line/lineStartbookkeeping. - Added a new
benchDeeplyIndentedQuerybenchmark case to quantify the optimization on indentation-heavy inputs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Language/Lexer.php | Bulk-skips runs of tab/space/comma via strspn() to reduce per-character overhead in whitespace scanning. |
| benchmarks/LexerBench.php | Adds an indentation-heavy benchmark to measure the whitespace-skipping optimization impact. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Collaborator
|
@copilot resolve the merge conflicts in this pull request |
Removed assignment of introspectionQuery in LexerBench.php.
Collaborator
|
Thanks @OpaqueRock! Released as v15.37.2. |
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.
Skip runs of horizontal whitespace in one scan in Lexer::positionAfterWhitespace
positionAfterWhitespace()currently advances one character at a time evenfor long runs of tabs, spaces, and commas — none of which affect line/column
tracking. This proposed change uses
strspn()to skip such runs in a single call, fallingthrough to the existing per-character handling for line breaks and the BOM.
Verified byte-identical token streams against the current implementation on
pretty-printed, minified, deeply-indented, and edge-case (BOM/CRLF/CR/blank
lines) inputs.
Added a
benchDeeplyIndentedQuerycase toLexerBenchto measure the effecton an indentation-heavy query: