perf(semantic): remove hash when checking identifier#17564
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 Performance ReportMerging #17564 will improve performance by 9.08%Comparing Summary
Benchmarks breakdown
Footnotes
|
camc314
left a comment
There was a problem hiding this comment.
using matches! might be faster? - the compiler should optimize it pretty nicely into a jump table
2d628c1 to
597f97e
Compare
597f97e to
fac3d94
Compare
This is amazing! |
There was a problem hiding this comment.
Pull request overview
This PR improves performance and compilation time by replacing the phf_set! macro with a simple match expression for checking strict mode reserved identifiers. For small lists like the 9 strict mode reserved words, direct pattern matching is more efficient than hashing.
Key Changes:
- Replaced
STRICT_MODE_NAMESphf set with inline match pattern for strict mode identifier validation - Refactored
check_identifierto use a single match expression for both "await" and strict mode checks - Removed
phfdependency fromoxc_semanticcrate
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/oxc_semantic/src/checker/javascript.rs | Refactored identifier checking logic to use match expressions instead of phf_set, removed STRICT_MODE_NAMES constant |
| crates/oxc_semantic/Cargo.toml | Removed phf dependency from both dependencies and dev-dependencies |
| Cargo.lock | Updated lockfile to reflect removal of phf from oxc_semantic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
`phf_set!` is good for large lists of strings, but in cases of small lists, it is often faster to just do a `.contains` or a `matches!`. It also slightly improves compile times since no work needs to be done to hash at compile time. It's possible the math on this might flip once we implement `Ident` (i.e., #16416), since the hashes will be pre-computed at parse-time.
fac3d94 to
6067143
Compare
### 🚀 Features - 659c23e linter: Init note field boilerplate (#17589) (Shrey Sudhir) - 6870b64 parser: Add TS1363 error code (#17609) (Sysix) - 23680a3 mangler: Skip mangling only in scopes affected by direct eval (#17612) (camc314) - a7e1643 parser: Add TS2528 error code to duplicate_default_export diagnostic (#17558) (camc314) ### 🐛 Bug Fixes - 1044116 ecmascript: Mark `new Symbol` as non side-effect free (#17568) (camc314) - ab5e4ca isolated-declarations: Strip default values from rest parameter binding patterns (#17602) (camc314) - 68b2e54 minifier: Prevent incorrect ??= transformation when member base is mutated (#17472) (copilot-swe-agent) ### ⚡ Performance - 6067143 semantic: Remove hash when checking identifier (#17564) (camchenry) - a28ab3d semantic: Avoid bounds check when checking string literal (#17545) (camc314) - 04809d1 semantic: Use SIMD for finding backslashes in `check_string_literal` (#17534) (camchenry) - 49ad2f0 semantic: Mark all diagnostic functions as `#[cold]` (#17487) (camc314) - ea82b50 transformer: Mark all diagnostic functions as `#[cold]` (#17486) (camc314) - d968e51 semantic: Mark `checker::check` as `inline(always)` (#17459) (camc314)



phf_set!is good for large lists of strings, but in cases of small lists, it is often faster to just do a.containsor amatches!. It also slightly improves compile times since no work needs to be done to hash at compile time.It's possible the math on this might flip once we implement
Ident(i.e., #16416), since the hashes will be pre-computed at parse-time.