tokenizer: Make consume_name faster. - #449
Merged
Merged
Conversation
Skip over runs of ascii and such in a tight loop. This is one of the hottest functions and match_byte! adds extra branches for the common cases.
emilio
enabled auto-merge
August 28, 2026 19:08
nicoburns
approved these changes
Aug 28, 2026
nicoburns
left a comment
Contributor
There was a problem hiding this comment.
This looks correct to me
Comment on lines
+950
to
+959
| // These are the overwhelmingly common bytes, that we can just skip over in a tight loop. | ||
| static IS_SIMPLE_NAME_BYTE: [bool; 256] = { | ||
| let mut table = [false; 256]; | ||
| let mut i = 0; | ||
| while i < 256 { | ||
| table[i as usize] = matches!(i as u8, b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9' | b'_' | b'-' | b'\xC0'..=b'\xEF'); | ||
| i += 1; | ||
| } | ||
| table | ||
| }; |
Contributor
There was a problem hiding this comment.
Given that this is a table of bool you could also try a bitset, and see if that's any faster.
Member
Author
There was a problem hiding this comment.
A bitset was quite a few more instructions: https://rust.godbolt.org/z/G94TTEo7G
|
|
||
| // start_pos is the end of the previous token, therefore at a code point boundary | ||
| let start_pos = tokenizer.position(); | ||
| let mut value_bytes; |
Contributor
There was a problem hiding this comment.
Nit: an explicit type annotation on value_bytes would nice.
Member
Author
There was a problem hiding this comment.
Gah I guess the auto-merge got faster. It's not a huge deal tho and it's pre-existing...
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 over runs of ascii and such in a tight loop. This is one of the hottest functions and match_byte! adds extra branches for the common cases.