Skip to content

perf(parser): check ASCII identifier characters without the ICU lookup - #5683

Open
g4lb wants to merge 2 commits into
boa-dev:mainfrom
g4lb:lexer-ascii-identifier-fast-path
Open

g4lb wants to merge 2 commits into
boa-dev:mainfrom
g4lb:lexer-ascii-identifier-fast-path

Conversation

@g4lb

@g4lb g4lb commented Nov 21, 2026

Copy link
Copy Markdown

It changes the following:

  • The identifier checks in the lexer used the ICU ID_Start / ID_Continue sets for every character. Now ASCII characters use a direct check. The tokens do not change.
Parser::parse_script Before After Change
v8-benches richards.js 782 µs 722 µs -7.7%
v8-benches deltablue.js 1.12 ms 1.03 ms -8.1%
v8-benches crypto.js 3.24 ms 3.05 ms -5.8%
3000 functions with member access 11.7 ms 10.3 ms -11.7%
identifiers with non-ASCII letters 3.82 ms 3.57 ms -6.4%

No benchmark was slower. I used 16 interleaved rounds of criterion (Apple M5, rustc 1.98.0).

Old and new ASTs matched on 1M random scripts.

@g4lb
g4lb requested a review from a team as a code owner November 21, 2026 11:40
@github-actions github-actions Bot added the Waiting On Review Waiting on reviews from the maintainers label Nov 21, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Nov 21, 2026
@github-actions github-actions Bot added the C-Parser Issues surrounding the parser label Nov 21, 2026
@zhuzhu81998

Copy link
Copy Markdown
Contributor

I mean it looks like a rather harmless optimization. But isnt the parser only called very few times (or even only once?) for a script?
If yes, it feels weird that this can have 5.8% effect on crypto.vs for example.

@g4lb

g4lb commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks. Yes, the parser runs once. The numbers are for parsing only, not for running the script.

@zhuzhu81998

zhuzhu81998 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

The numbers are for parsing only, not for running the script.

Ahh makes sense sorry. completely ignored the headers of the table XD

@abdulhamid999 abdulhamid999 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice optimization! The ASCII fast path matches ECMAScript §12.7 nicely since \UnicodeIDStart\ in ASCII is strictly [A-Za-z]\ and \UnicodeIDContinue\ in ASCII is strictly [0-9A-Za-z_].

One tiny detail in \is_identifier_part: since \ch < 0x80\ returns early, \

@abdulhamid999

Copy link
Copy Markdown

One tiny detail in is_identifier_part: since ch < 0x80 returns early, 0x0024 ($) and 0x005F (_) in the subsequent matches!(ch, 0x0024 | 0x005F | 0x200C | 0x200D) can never be hit on the fallback path. You could simplify that fallback to matches!(ch, 0x200C /* <ZWNJ> */ | 0x200D /* <ZWJ> */), mirroring how is_identifier_start doesn't repeat the ASCII characters in its fallback.

@g4lb

g4lb commented Nov 23, 2026

Copy link
Copy Markdown
Author

@abdulhamid999 Thanks. Done in 10c2bd9.

@abdulhamid999

Copy link
Copy Markdown

Looks great! The fallback is much cleaner now without the unreachable checks. Thanks for the quick update!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Parser Issues surrounding the parser Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants