-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Speed up Parser::expected_tokens
#133793
Speed up Parser::expected_tokens
#133793
Conversation
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…, r=<try> Speed up `Parser::expected_tokens` r? `@ghost`
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (4e6952e): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking 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 may lead to changes in compiler perf. @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary -1.2%, secondary 1.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -1.5%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 767.333s -> 766.554s (-0.10%) |
0133601
to
f5482df
Compare
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
Best reviewed one commit at a time. Let's re-run perf just to be sure: @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…, r=<try> Speed up `Parser::expected_tokens` The constant pushing/clearing of `Parser::expected_tokens` during parsing is slow. This PR speeds it up greatly. r? `@estebank`
/// We really want to keep the number of variants to 128 or fewer, sot that | ||
/// `TokenTypeSet` can be implemented with a `u128`. |
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.
On the one hand, we should be able to do so. On the other, I can see this becoming a point of contention with t-lang in the medium future if we push back on a feature for this reason :)
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.
The 17 asm symbols would be a good place to cut things down if necessary. I'm a bit annoyed that they are even in there; so many of them for such a rare use case.
// This assertion will detect if this method and the type definition get out of sync. | ||
assert_eq!(token_type as u32, val); | ||
token_type |
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.
Can't the function just be the as
cast with a <=104
check?
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.
No. You can convert a C-style enum to an integer with as
, but you can't convert in the other direction, e.g. as per this StackOverflow answer. There are proc macros to do it, but that answer pointed out an alternative that is suitable here: transmute
is fine so long as the enum is repr(uN)
for some value of N
. So I will do that with repr(u8)
, which will cut over 100 lines of code, yay.
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.
Should we have a static assertion that all of them roundtrip? I'm always concerned about a careless future reformat breaking the bidirectional mapping.
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.
I'd be happy for extra protection, but I'm having trouble imagining what such a static assertion would look like. Can you explain more?
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.
Alternatively, I can go back to an explicit match. The StackOverflow answer mentioned this style:
match v {
x if x == MyEnum::A as i32 => Ok(MyEnum::A),
x if x == MyEnum::B as i32 => Ok(MyEnum::B),
x if x == MyEnum::C as i32 => Ok(MyEnum::C),
_ => Err(()),
}
It requires a line for every variant, but avoids having to write a number on each line.
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.
I'd be happy for extra protection, but I'm having trouble imagining what such a static assertion would look like. Can you explain more?
I'd forgotten that the range operation doesn't work today in const, but I was picturing something like:
const __CHECK: () = const {
for i in 0..2 {
assert_eq!(E::to_i32(&E::from_i32(i)), i);
}
};
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.
I've gone with the guard-based version, using a macro to avoid excessive boilerplate. It doesn't rely on unsafe
, and also doesn't rely on matching up the right integer with the right variant.
I'll finish reviewing tomorrow |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
@bors r=spastorino |
…, r=spastorino Speed up `Parser::expected_tokens` The constant pushing/clearing of `Parser::expected_tokens` during parsing is slow. This PR speeds it up greatly. r? `@estebank`
Some try jobs are not getting picked up correctly, trying a sync cc https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra/topic/try.20jobs.20not.20kicking.20off. |
@bors r- retry (sync) |
The tree seems to be back open? @bors r=spastorino |
Oops yeah, sorry about that -- bors picked up treeclosed from another PR, and I lost track of this PR due to notifications flood... |
☀️ Test successful - checks-actions |
Finished benchmarking commit (9e136a3): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary -0.1%, secondary -0.9%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -1.2%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 769.451s -> 766.727s (-0.35%) |
I just got the same error with 280 on powerpc64le in a Fedora scratch build of 1.85.0-beta.5: I have no idea why it would be different than Rust CI though, which apparently did pass on that arch... |
I think the difference is due to the alignment of |
I figured it out -- #134115 changed ppc64 alignment regardless of LLVM version, but when I'm building natively it's starting with the old alignment in stage0, while Rust CI only cross-compiles using the last stage. |
The constant pushing/clearing of
Parser::expected_tokens
during parsing is slow. This PR speeds it up greatly.r? @estebank