Skip to content

tokenizer: Make consume_name faster. - #449

Merged
emilio merged 1 commit into
mainfrom
consume-name-fast
Aug 28, 2026
Merged

tokenizer: Make consume_name faster.#449
emilio merged 1 commit into
mainfrom
consume-name-fast

Conversation

@emilio

@emilio emilio commented Aug 28, 2026

Copy link
Copy Markdown
Member

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.

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.

@nicoburns nicoburns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct to me

Comment thread src/tokenizer.rs
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
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is a table of bool you could also try a bitset, and see if that's any faster.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bitset was quite a few more instructions: https://rust.godbolt.org/z/G94TTEo7G

Comment thread src/tokenizer.rs

// start_pos is the end of the previous token, therefore at a code point boundary
let start_pos = tokenizer.position();
let mut value_bytes;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: an explicit type annotation on value_bytes would nice.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah I guess the auto-merge got faster. It's not a huge deal tho and it's pre-existing...

@emilio
emilio added this pull request to the merge queue Aug 28, 2026
Merged via the queue into main with commit 9b3fbd4 Aug 28, 2026
14 checks passed
@emilio
emilio deleted the consume-name-fast branch August 29, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants