Skip to content
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

Merged
merged 1 commit into from
Apr 6, 2023
Merged

Use FieldIdx in FieldsShape #109915

merged 1 commit into from
Apr 6, 2023

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Apr 3, 2023

Finally got to the main motivating example from rust-lang/compiler-team#606 :)

@scottmcm scottmcm marked this pull request as ready for review April 3, 2023 22:24
@rustbot
Copy link
Collaborator

rustbot commented Apr 3, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot
Copy link
Collaborator

rustbot commented Apr 3, 2023

r? @oli-obk

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 3, 2023
@@ -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>),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooray for fixing FIXMEs 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> {
Copy link
Member Author

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.

Comment on lines 196 to 187
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))
};
Copy link
Contributor

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 :)
@oli-obk
Copy link
Contributor

oli-obk commented Apr 5, 2023

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 5, 2023
@bors
Copy link
Contributor

bors commented Apr 5, 2023

⌛ Trying commit 21bb8ef with merge 6aaacfc5ec967a8d7adb686522f6e9f06d0f07f6...

@bors
Copy link
Contributor

bors commented Apr 5, 2023

☀️ Try build successful - checks-actions
Build commit: 6aaacfc5ec967a8d7adb686522f6e9f06d0f07f6 (6aaacfc5ec967a8d7adb686522f6e9f06d0f07f6)

1 similar comment
@bors
Copy link
Contributor

bors commented Apr 5, 2023

☀️ Try build successful - checks-actions
Build commit: 6aaacfc5ec967a8d7adb686522f6e9f06d0f07f6 (6aaacfc5ec967a8d7adb686522f6e9f06d0f07f6)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6aaacfc5ec967a8d7adb686522f6e9f06d0f07f6): comparison URL.

Overall result: ✅ improvements - no action needed

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 may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.2% [1.4%, 2.9%] 3
Improvements ✅
(primary)
-3.2% [-3.2%, -3.2%] 1
Improvements ✅
(secondary)
-0.9% [-0.9%, -0.9%] 1
All ❌✅ (primary) -3.2% [-3.2%, -3.2%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 5, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Apr 5, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Apr 5, 2023

📌 Commit 21bb8ef has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 5, 2023
@bors
Copy link
Contributor

bors commented Apr 6, 2023

⌛ Testing commit 21bb8ef with merge 2824db3...

@bors
Copy link
Contributor

bors commented Apr 6, 2023

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 2824db3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 6, 2023
@bors bors merged commit 2824db3 into rust-lang:master Apr 6, 2023
@rustbot rustbot added this to the 1.70.0 milestone Apr 6, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2824db3): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.7% [3.3%, 4.0%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.6% [-2.6%, -2.6%] 1
All ❌✅ (primary) - - 0

Cycles

Results

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.0% [2.0%, 5.2%] 13
Improvements ✅
(primary)
-0.8% [-0.8%, -0.8%] 1
Improvements ✅
(secondary)
-4.0% [-4.4%, -3.4%] 3
All ❌✅ (primary) -0.8% [-0.8%, -0.8%] 1

@scottmcm scottmcm deleted the layout-indexvec branch April 6, 2023 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants