Skip to content

Conversation

@yotamofek
Copy link
Contributor

In compute_layout, there were a bunch of collections (IndexVecs) that were being created by pushing in a loop, instead of a, hopefully, more performant usage of iterator combinators. Second commit is just a small cleanup.

I'd love a perf run to see if this shows up in benchmarks.

@rustbot
Copy link
Collaborator

rustbot commented Oct 18, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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 Oct 18, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 18, 2025

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Kobzol
Copy link
Member

Kobzol commented Oct 18, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 18, 2025
Micro-optimization attempt in coroutine layout computation
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 18, 2025
@cjgillot
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 18, 2025
Micro-optimization attempt in coroutine layout computation
@rust-bors

This comment has been minimized.


// Gather live local types and their indices.
let mut locals = IndexVec::<CoroutineSavedLocal, _>::new();
let mut tys = IndexVec::<CoroutineSavedLocal, _>::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do simpler? The original code but using IndexVec::with_capacity?

// Build the coroutine variant field list.
// Create a map from local indices to coroutine struct indices.
let mut variant_fields: IndexVec<VariantIdx, IndexVec<FieldIdx, CoroutineSavedLocal>> =
iter::repeat(IndexVec::new()).take(CoroutineArgs::RESERVED_VARIANTS).collect();
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of pushing, could we use IndexVec::from_elem_n(IndexVec::new(), CoroutineArgs::RESERVED_VARIANTS + live_locals_at_suspension_points.len())? And then assign to each element?

@yotamofek
Copy link
Contributor Author

@cjgillot both suggestions sound good, but I'd like to try them after this perf run to see if they have any effect on it

@rust-bors
Copy link

rust-bors bot commented Oct 18, 2025

☀️ Try build successful (CI)
Build commit: 32cc823 (32cc823f9cad9f0599aac2707d559bed821f7548, parent: 6380899f32599ea25615d4ccd708d0e8da652b0c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (32cc823): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

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

Instruction count

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

Max RSS (memory usage)

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

Cycles

Results (primary 2.4%, secondary 3.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Binary size

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

Bootstrap: 471.955s -> 474.126s (0.46%)
Artifact size: 390.54 MiB -> 390.51 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 19, 2025
@yotamofek yotamofek force-pushed the pr/mir/coroutine-layout-opt branch from 6f682c2 to a67c615 Compare October 19, 2025 19:47
@rustbot
Copy link
Collaborator

rustbot commented Oct 19, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@yotamofek
Copy link
Contributor Author

@cjgillot might have gone a bit overboard here with the izip, but it does make that loop body more succinct. WDYT?

I don't mind just closing this PR since it doesn't affect perf, maybe it's not worth touching this at all.

@jdonszelmann
Copy link
Contributor

r? compiler

@rustbot rustbot assigned davidtwco and unassigned jdonszelmann Oct 20, 2025
@davidtwco
Copy link
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 25, 2025
Micro-optimization attempt in coroutine layout computation
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 25, 2025
@rust-bors
Copy link

rust-bors bot commented Oct 25, 2025

☀️ Try build successful (CI)
Build commit: f6307c2 (f6307c2d83816dc4bc953e2b19d09b0ecd4cc041, parent: 04ff05c9c0cfbca33115c5f1b8bb20a66a54b799)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f6307c2): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

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

Instruction count

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

Max RSS (memory usage)

Results (primary 0.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Cycles

Results (secondary -4.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Binary size

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

Bootstrap: 473.373s -> 475.989s (0.55%)
Artifact size: 390.48 MiB -> 390.45 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 25, 2025
@cjgillot
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 30, 2025

📌 Commit a67c615 has been approved by cjgillot

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 Oct 30, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 30, 2025
…opt, r=cjgillot Micro-optimization attempt in coroutine layout computation In `compute_layout`, there were a bunch of collections (`IndexVec`s) that were being created by `push`ing in a loop, instead of a, hopefully, more performant usage of iterator combinators. [Second commit](rust-lang@6f682c2) is just a small cleanup. I'd love a perf run to see if this shows up in benchmarks.
bors added a commit that referenced this pull request Oct 30, 2025
Rollup of 9 pull requests Successful merges: - #138217 (Turn `Cow::is_borrowed,is_owned` into associated functions.) - #147858 (Micro-optimization attempt in coroutine layout computation) - #147923 (Simplify rustc_public context handling) - #147935 (Add LLVM realtime sanitizer) - #148115 (rustdoc: Rename unstable option `--nocapture` to `--no-capture` in accordance with `libtest`) - #148137 (Couple of changes for Redox OS) - #148176 ([rustdoc] Include attribute and derive macros when filtering on "macros") - #148193 (Remove `QPath::LangItem`) - #148253 (Handle default features and -Ctarget-features in the dummy backend) r? `@ghost` `@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Oct 30, 2025
Rollup of 8 pull requests Successful merges: - #138217 (Turn `Cow::is_borrowed,is_owned` into associated functions.) - #147858 (Micro-optimization attempt in coroutine layout computation) - #147923 (Simplify rustc_public context handling) - #148115 (rustdoc: Rename unstable option `--nocapture` to `--no-capture` in accordance with `libtest`) - #148137 (Couple of changes for Redox OS) - #148176 ([rustdoc] Include attribute and derive macros when filtering on "macros") - #148253 (Handle default features and -Ctarget-features in the dummy backend) - #148272 (Align VEX V5 boot routine to 4 bytes) r? `@ghost` `@rustbot` modify labels: rollup
@bors bors merged commit 1ae00ba into rust-lang:master Oct 30, 2025
12 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Oct 30, 2025
rust-timer added a commit that referenced this pull request Oct 30, 2025
Rollup merge of #147858 - yotamofek:pr/mir/coroutine-layout-opt, r=cjgillot Micro-optimization attempt in coroutine layout computation In `compute_layout`, there were a bunch of collections (`IndexVec`s) that were being created by `push`ing in a loop, instead of a, hopefully, more performant usage of iterator combinators. [Second commit](6f682c2) is just a small cleanup. I'd love a perf run to see if this shows up in benchmarks.
@yotamofek yotamofek deleted the pr/mir/coroutine-layout-opt branch October 30, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

8 participants