-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
perf(es/parser): Optimize skip_space
#11225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 0a74aa1 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Binary Sizes
Commit: 5776883 |
CodSpeed Performance ReportMerging #11225 will improve performances by 11.63%Comparing Summary
Benchmarks breakdown
Footnotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the whitespace and comment skipping logic in the ECMAScript lexer by consolidating the implementation into a table-driven approach using byte handlers. The refactoring removes the separate SkipWhitespace struct and moves all whitespace handling directly into the Lexer implementation.
- Introduces helper functions
is_irregular_whitespaceandis_irregular_line_terminatorfor Unicode whitespace detection - Replaces the old
skip_spacemethod's generic parameter with a simpler implementation using byte handler lookup table - Consolidates comment handling directly into the byte handler for
/(slash) characters
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/swc_ecma_parser/src/lexer/whitespace.rs | Major refactoring - removes SkipWhitespace struct, adds Unicode whitespace helper functions, implements new table-driven byte handlers, and moves skip_space method into Lexer impl |
| crates/swc_ecma_parser/src/lexer/table.rs | Formatting change - adds #[rustfmt::skip] attribute and adjusts comment alignment |
| crates/swc_ecma_parser/src/lexer/state.rs | Removes generic type parameter from skip_space method calls |
| crates/swc_ecma_parser/src/lexer/mod.rs | Removes generic type parameter from skip_space method calls and removes the old skip_space implementation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kdy1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvement! Thanks!
skip_spaceskip_space
skip_spaceskip_space
|
Impressive optimization! |
Description:
matchto deal with spaces and newlines, and used a jump table when encountering Unicode characters. Now, everything is handled in a single loop, all match statements are removed, and everything goes through the jump table.had_line_breakis set to true. At this point, it can also skip over any following spaces and newlines continuously, since thehad_line_breakstate only needs to be set once.