Skip to content

Vec refactor and optimization of panic guards - #161426

Open
fereidani wants to merge 3 commits into
rust-lang:mainfrom
fereidani:vec_mod_refactor
Open

Vec refactor and optimization of panic guards#161426
fereidani wants to merge 3 commits into
rust-lang:mainfrom
fereidani:vec_mod_refactor

Conversation

@fereidani

@fereidani fereidani commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Hey, this is a follow-up to our PR #149784.

I want to:

  1. Rename FillGapOnDrop of dedup_by to PanicGuard, IMHO this is a better name and matches the retain_mut.
  2. I forgot to add #[inline(never)] for drop of panic guard of retain_mut in my original PR, I've added that.
  3. I've done the same for drop of panic guard of dedup_by and I've added both #[cold] and #[inline(never)]

As drops are only triggered for panic case, It should not affect performance for non-panic common case.

I expect slight binary size reduction.

r? joboet

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 20, 2026
@rustbot

rustbot commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

joboet is currently at their maximum review capacity.
They may take a while to respond.

@joboet

joboet commented Aug 27, 2026

Copy link
Copy Markdown
Member
  1. Rename FillGapOnDrop of dedup_by to PanicGuard, IMHO this is a better name and matches the retain_mut.

While consistency is nice, descriptiveness is even better – as such I think FillGapOnDrop is the better name. And the shortening from gap to g isn't by any means significant enough to warrant the reduced legibility.

  1. I forgot to add #[inline(never)] for drop of panic guard of retain_mut in my original PR, I've added that.

In most cases, #[cold] suffices. Do you have any concrete examples where this turns up?

  1. I've done the same for drop of panic guard of dedup_by and I've added both #[cold] and #[inline(never)]

As it is only called in catch-pads, I don't know how relevant this is. For these kinds of things it's always a good idea to look at the assembly and see whether your intuition is correct.

@fereidani

Copy link
Copy Markdown
Contributor Author

It seems it reduces retain function body size at least in this godbolt test: https://godbolt.org/z/vGbP9P6WT
I think it might help in general cases where multiple of this panic handler would have been inlined in the user code, I'll request a perf run to see if it is effective.

@Kobzol

Kobzol commented Aug 27, 2026

Copy link
Copy Markdown
Member

@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 Aug 27, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 27, 2026
Vec refactor and optimization of panic guards
@rust-bors

rust-bors Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

β˜€οΈ Try build successful (CI)
Build commit: 0a61e4d (0a61e4dd1357c41f0deb96d302381aea3013290b)
Base parent: e457a7b (e457a7b0d326d67b4322ef0d11bd715cfaeda48f)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (0a61e4d): comparison URL.

Overall result: βœ… improvements - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@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
Improvements βœ…
(primary)
- - 0
Improvements βœ…
(secondary)
-0.1% [-0.1%, -0.1%] 2
All βŒβœ… (primary) - - 0

Max RSS (memory usage)

Results (primary 2.8%, secondary -4.2%)

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

mean range count
Regressions ❌
(primary)
2.8% [2.8%, 2.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements βœ…
(primary)
- - 0
Improvements βœ…
(secondary)
-4.2% [-6.6%, -1.8%] 2
All βŒβœ… (primary) 2.8% [2.8%, 2.8%] 1

Cycles

Results (primary 0.3%, secondary 2.5%)

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

mean range count
Regressions ❌
(primary)
2.7% [2.3%, 3.0%] 2
Regressions ❌
(secondary)
2.5% [2.5%, 2.5%] 1
Improvements βœ…
(primary)
-2.0% [-2.1%, -2.0%] 2
Improvements βœ…
(secondary)
- - 0
All βŒβœ… (primary) 0.3% [-2.1%, 3.0%] 4

Binary size

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

Bootstrap: 476.343s -> 473.583s (-0.58%)
Artifact size: 402.74 MiB -> 402.81 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 27, 2026
@rust-bors

rust-bors Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

β˜” The latest upstream changes (presumably #161990) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants