perf(parser): remove string search from parsing JSX element name#23713
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. |
There was a problem hiding this comment.
Pull request overview
Optimizes JSX parsing in oxc_parser by avoiding per-identifier string searches for '-' when classifying JSX element names, instead reusing information already available during lexing.
Changes:
- Changed
parse_jsx_identifierto return(JSXIdentifier, contains_dash)so callers can avoidname.contains('-'). - Updated JSX element-name classification and member-expression parsing to use
contains_dash. - Updated
continue_lex_jsx_identifierto return aboolindicating whether retokenization occurred.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/oxc_parser/src/jsx/mod.rs | Propagates a lexer-derived contains_dash flag through JSX identifier parsing to eliminate name.contains('-') searches. |
| crates/oxc_parser/src/cursor.rs | Makes continue_lex_jsx_identifier return a boolean so the parser can cheaply detect hyphenated JSX identifiers. |
Merging this PR will not alter performance
Comparing Footnotes
|
Merge activity
|
) Optimization to parsing JSX. When parsing JSX element names `parse_jsx_element_name` has to determine if the identifier: 1. starts with a lowercase letter, and 2. contains a `-`. The 2nd check is relatively expensive - string search. Avoid the search by making the lexer feed this information (which it already has) to the parser. This reduces the check in the parser to just `!contains_dash`. (came across this while working #23712)
0338837 to
10b96c6
Compare

Optimization to parsing JSX.
When parsing JSX element names
parse_jsx_element_namehas to determine if the identifier:-.The 2nd check is relatively expensive - string search.
Avoid the search by making the lexer feed this information (which it already has) to the parser. This reduces the check in the parser to just
!contains_dash.(came across this while working on #23712)