-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Use FieldIdx
in FieldsShape
#109915
Use FieldIdx
in FieldsShape
#109915
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
r? @oli-obk (rustbot has picked a reviewer for you, use r? to override) |
@@ -492,8 +481,7 @@ fn layout_of_uncached<'tcx>( | |||
enum SavedLocalEligibility { | |||
Unassigned, | |||
Assigned(VariantIdx), | |||
// FIXME: Use newtype_index so we aren't wasting bytes | |||
Ineligible(Option<u32>), | |||
Ineligible(Option<FieldIdx>), |
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.
Hooray for fixing FIXME
s from 2019 🙂
/// and `inverse_memory_index` (memory order to source field order). | ||
/// See also `FieldsShape::Arbitrary::memory_index` for more details. | ||
// FIXME(eddyb) build a better abstraction for permutations, if possible. | ||
pub fn invert_bijective_mapping(&self) -> IndexVec<J, 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.
This code was in three places (the two obvious ones and https://github.com/rust-lang/rust/pull/109915/files#diff-bd58d97c1958029df344a30d473950e0195516d1153cbcc6314ff01afb87d12aR1191), so I figured promoting it to here was reasonable enough.
compiler/rustc_abi/src/layout.rs
Outdated
let memory_index = if optimize { | ||
inverse_memory_index.invert_bijective_mapping() | ||
} else { | ||
debug_assert!(inverse_memory_index.iter().copied().eq(fields.indices())); | ||
IndexVec::from_raw(transmute_index_vec(inverse_memory_index.raw)) | ||
}; |
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 think the right optimization here may be to turn the memory_index
field into an Option
and if it's none, just use the index you would have used to index into it instead of actually having a vec![0, 1, 2, 3, ...]
for all the common use cases.
It should also not be terribly hot, so yea, please use a safe version of this and we can look into optimizing it as a follow-up
Finally got to the main motivating example from the MCP :)
e41b45d
to
21bb8ef
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 21bb8ef with merge 6aaacfc5ec967a8d7adb686522f6e9f06d0f07f6... |
☀️ Try build successful - checks-actions |
1 similar comment
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (6aaacfc5ec967a8d7adb686522f6e9f06d0f07f6): 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 a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (2824db3): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
|
Finally got to the main motivating example from rust-lang/compiler-team#606 :)