Skip to content

Usually avoid the sort in WrappingRange::smallest_range_containing - #160674

Open
scottmcm wants to merge 1 commit into
rust-lang:mainfrom
scottmcm:wait-what-happened
Open

Usually avoid the sort in WrappingRange::smallest_range_containing#160674
scottmcm wants to merge 1 commit into
rust-lang:mainfrom
scottmcm:wait-what-happened

Conversation

@scottmcm

@scottmcm scottmcm commented Aug 7, 2026

Copy link
Copy Markdown
Member

I wasn't planning on touching this again, but I had a shower thought: we've been sorting these for a while because that's better than doing a quadratic check for usable wraparound ranges, but actually we often don't need to.

So long as the obvious min..=max range is small enough, we don't need to bother even looking for a wrapping range!

Now, I don't think this code is particularly hot -- you'd need lots of enums or particularly big ones before it would really matter -- but this does let us short-circuit for even fairly complex enums like mem::alignment.


  • I did not use an LLM to create a change in this PR.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 7, 2026
@scottmcm

scottmcm commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 7, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 7, 2026
Usually avoid the sort in `WrappingRange::smallest_range_containing`
@rust-bors

rust-bors Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: d0d0b8b (d0d0b8bc325afb707fbc76fb45f437b5d32c6ce4)
Base parent: 88f7399 (88f7399cb4912680976e1c342ea7661b9dc84940)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (d0d0b8b): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

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

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

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

Max RSS (memory usage)

Results (primary 1.1%, secondary -0.5%)

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

mean range count
Regressions ❌
(primary)
4.9% [4.9%, 4.9%] 1
Regressions ❌
(secondary)
3.1% [0.4%, 5.8%] 2
Improvements ✅
(primary)
-2.7% [-2.7%, -2.7%] 1
Improvements ✅
(secondary)
-1.1% [-5.7%, -0.4%] 12
All ❌✅ (primary) 1.1% [-2.7%, 4.9%] 2

Cycles

Results (secondary -0.7%)

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.9% [0.4%, 2.3%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.4% [-6.9%, -0.4%] 19
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 460.09s -> 458.727s (-0.30%)
Artifact size: 398.62 MiB -> 398.67 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 7, 2026
@scottmcm
scottmcm marked this pull request as ready for review August 7, 2026 20:29
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 7, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 7, 2026
@rustbot

rustbot commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: codegen, compiler
  • codegen, compiler expanded to 75 candidates
  • Random selection from 19 candidates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants