-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Optimize rustc_lexer
#91393
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
Optimize rustc_lexer
#91393
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 89bc19127c3cd88ad0ecae2957206172993729fe with merge f5bcd39ff4304330b2f8d73eced51275ccac2db6... |
☀️ Try build successful - checks-actions |
Queued f5bcd39ff4304330b2f8d73eced51275ccac2db6 with parent 1c02878, future comparison URL. |
Finished benchmarking commit (f5bcd39ff4304330b2f8d73eced51275ccac2db6): comparison url. Summary: This change led to moderate relevant improvements 🎉 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf. @bors rollup=never |
Perf says it's a 0.3% to 0.9% improvement, without any regressions. That's actually better than I expected :-) |
and optimize the iterator returned by `tokenize(). This improves lexer performance by 35%
89bc191
to
1f147a2
Compare
@bors r+ |
📌 Commit 1f147a2 has been approved by |
|
||
/// Eats symbols while predicate returns true or until the end of file is reached. | ||
pub(crate) fn eat_while(&mut self, mut predicate: impl FnMut(char) -> bool) { | ||
// It was tried making optimized version of this for eg. line comments, but |
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.
// It was tried making optimized version of this for eg. line comments, but | |
// There was an attempt to make an optimized version of this for e.g. line comments, but |
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.
That would have worked to.
But sorry, I saw this to late.
☀️ Test successful - checks-actions |
Finished benchmarking commit (2a9e083): comparison url. Summary: This change led to moderate relevant improvements 🎉 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
The
cursor.first()
method inrustc_lexer
now calls thechars.next()
method instead ofchars.nth_char(0)
.This allows LLVM to optimize the code better. The biggest win is that
eat_while()
is now fully inlined and generates better assembly. This improves the lexer's performance by 35% in a micro-benchmark I made (Lexing all 18MB of code in the compiler directory). But lexing is only a small part of the overall compilation time, so I don't know how significant it is.Big thanks to criterion and
cargo asm
.