perf(parser): remove -> Result<T> from all parsing methods#10588
Merged
graphite-app[bot] merged 1 commit intomainfrom Apr 24, 2025
Merged
perf(parser): remove -> Result<T> from all parsing methods#10588graphite-app[bot] merged 1 commit intomainfrom
-> Result<T> from all parsing methods#10588graphite-app[bot] merged 1 commit intomainfrom
Conversation
Member
Author
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. |
Boshen
commented
Apr 24, 2025
CodSpeed Instrumentation Performance ReportMerging #10588 will improve performances by 7.9%Comparing Summary
Benchmarks breakdown
|
Contributor
Merge activity
|
All credits to @overlookmotel In parser, optimize for common case that file parses successfully. Instead of parse_* methods returning Result<T>s which are checked with ? in the caller, always return a valid node T. In case of a fatal parsing error: Record the error in fatal_error property of ParserImpl. Also record current length of errors. Fast forward the lexer to EOF, so parsing will come to an end swiftly. Create a dummy node of the required type and return it. At end of parsing, if fatal_error.is_some(), then there was a fatal error. In that case: Truncate errors to the length it was at time of the fatal error (because more errors may occur as the parser finds it's unexpectedly at EOF). Add fatal_error to errors. i.e. all parse methods never fail, they just return nonsense if there's a fatal error. This removes all the branches implicit in `?`. --- Wall clock benchmark: ``` oxc main ❯ hyperfine './target/release/examples/parser-new ./target/typescript.js' './target/release/examples/parser ./target/typescript.js' Benchmark 1: ./target/release/examples/parser-new ./target/typescript.js Time (mean ± σ): 42.7 ms ± 2.1 ms [User: 36.7 ms, System: 5.3 ms] Range (min … max): 41.6 ms … 59.6 ms 68 runs Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options. Benchmark 2: ./target/release/examples/parser ./target/typescript.js Time (mean ± σ): 44.2 ms ± 0.7 ms [User: 38.3 ms, System: 5.4 ms] Range (min … max): 43.7 ms … 48.6 ms 64 runs Summary ./target/release/examples/parser-new ./target/typescript.js ran 1.04 ± 0.05 times faster than ./target/release/examples/parser ./target/typescript.js ``` /usr/bin/time -al: ``` old: 517424069 instructions retired new: 492334561 instructions retired ``` uses 5% less CPU instructions. --- Did some fuzzing with https://github.com/oxc-project/fuzz-oxc, found no crashes.
8f7bb53 to
e228840
Compare
c44c732 to
4f56b2c
Compare
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

All credits to @overlookmotel
In parser, optimize for common case that file parses successfully.
Instead of parse_* methods returning Results which are checked with
?in the caller, always return a valid node T.In case of a fatal parsing error:
fatal_error.is_some(), then there was a fatal error. In that case:Truncate errors to the length it was at time of the fatal error (because more errors may occur as the parser finds it's unexpectedly at EOF).
Add fatal_error to errors.
i.e. all parse methods never fail, they just return nonsense if there's a fatal error. This removes all the branches implicit in
?.Wall clock benchmark:
/usr/bin/time -al:
uses 5% less CPU instructions.
Testing: