-
-
Notifications
You must be signed in to change notification settings - Fork 721
perf(lexer): only check for hashbang at start of file #12521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(lexer): only check for hashbang at start of file #12521
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #12521 will improve performances by 8.47%Comparing Summary
Benchmarks breakdown
|
875bccc to
41cb852
Compare
camc314
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice 💪
|
Hmm. I'm not sure that benchmark is right. First version made no difference at all. I may have made a mistake. |
41cb852 to
c181f5f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes the lexer by restricting hashbang comment detection to only the first token of a file. Since hashbang comments can only appear at the very start of a file, this eliminates unnecessary checks for every # character encountered during lexing.
- Adds a dedicated
first_token()method that specifically checks for hashbang comments - Simplifies the
#byte handler to only handle private identifiers - Updates parser and benchmark code to use the new
first_token()method
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tasks/benchmark/benches/lexer.rs | Updates benchmark to use first_token() method and adds EOF check |
| crates/oxc_parser/src/lib.rs | Replaces bump_any() with first_token() call in parser initialization |
| crates/oxc_parser/src/lexer/mod.rs | Adds new first_token() method and inlines read_next_token() |
| crates/oxc_parser/src/lexer/comment.rs | Makes read_hashbang_comment() unsafe and removes unnecessary line setting |
| crates/oxc_parser/src/lexer/byte_handlers.rs | Simplifies # handler to only process private identifiers |
Merge activity
|
Small optimization to lexer. A hashbang can only appear at very start of file, so only check for hashbang when getting first token. This streamlines the byte handler for `#`, because a `#` anywhere else can only be a private identifier. Note: `self.token.set_is_on_new_line(true);` in `read_hashbang_comment` is not required, because it's always `true` already.
c181f5f to
47a565f
Compare
) Small optimization to lexer. A hashbang can only appear at very start of file, so only check for hashbang when getting first token. This streamlines the byte handler for `#`, because a `#` anywhere else can only be a private identifier. Note: `self.token.set_is_on_new_line(true);` in `read_hashbang_comment` is not required, because it's always `true` already.

Small optimization to lexer. A hashbang can only appear at very start of file, so only check for hashbang when getting first token. This streamlines the byte handler for
#, because a#anywhere else can only be a private identifier.Note:
self.token.set_is_on_new_line(true);inread_hashbang_commentis not required, because it's alwaystruealready.