Skip to content

Reserve items in Extend implementations - #162495

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
JonathanBrouwer:reserve-mono-extend
Sep 9, 2026
Merged

Reserve items in Extend implementations#162495
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
JonathanBrouwer:reserve-mono-extend

Conversation

@JonathanBrouwer

@JonathanBrouwer JonathanBrouwer commented Sep 8, 2026

Copy link
Copy Markdown
Member

This might be a perf win, inspired by @Kobzol's approach in this PR: #162480

@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 Sep 8, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member Author

@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 Sep 8, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 8, 2026
Reserve items in `Extend` implementation of `MonoItems`
@JonathanBrouwer

Copy link
Copy Markdown
Member Author

Searched in the compiler for more places to do this
@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 8, 2026
Reserve items in `Extend` implementation of `MonoItems`
@JonathanBrouwer JonathanBrouwer changed the title Reserve items in Extend implementation of MonoItems Reserve items in Extend implementations Sep 8, 2026
@rust-bors

rust-bors Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 5653ff1 (5653ff1472c1fbac81b5ce04e505360b28b0af67)
Base parent: b505807 (b505807a88bdb0dca9c968155f2167a927dddb34)

@rust-timer

This comment has been minimized.

@Kobzol

Kobzol commented Sep 8, 2026

Copy link
Copy Markdown
Member

Nice finds! Just noting that in case the data structure was previously cleared or its size reduced, this might overallocate. The exact size to allocate should be something like items.len() - (self.capacity() - self.len()).

@JonathanBrouwer

JonathanBrouwer commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

Per the documentation of reserve(n), it ensures there is space for at least n more elements than the length (not capacity!) of the current collection.

https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.reserve

So given that, I don't think you're right

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (5653ff1): 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.3% [-0.4%, -0.2%] 6
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 0.4%)

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

mean range count
Regressions ❌
(primary)
1.4% [0.5%, 3.2%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.2% [-1.7%, -0.6%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [-1.7%, 3.2%] 5

Cycles

Results (primary 0.2%, secondary -3.7%)

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

mean range count
Regressions ❌
(primary)
1.0% [0.5%, 2.1%] 7
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.5% [-0.7%, -0.4%] 7
Improvements ✅
(secondary)
-3.7% [-3.7%, -3.7%] 1
All ❌✅ (primary) 0.2% [-0.7%, 2.1%] 14

Binary size

Results (primary -0.0%, secondary -0.0%)

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.0% [-0.0%, -0.0%] 7
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 1
All ❌✅ (primary) -0.0% [-0.0%, -0.0%] 7

Bootstrap: 477.178s -> 480.938s (0.79%)
Artifact size: 403.53 MiB -> 403.61 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 8, 2026
@JonathanBrouwer
JonathanBrouwer marked this pull request as ready for review September 8, 2026 21:12
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 8, 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 Sep 8, 2026
@rustbot

rustbot commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

r? @wesleywiser

rustbot has assigned @wesleywiser.
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: compiler
  • compiler expanded to 76 candidates
  • Random selection from 21 candidates

@JonathanBrouwer

Copy link
Copy Markdown
Member Author

The include-blob results are noise, but if you also show non-relevant results it is quite green, so I think this is worth merging

@Kobzol

Kobzol commented Sep 8, 2026

Copy link
Copy Markdown
Member

Ah, sorry, I got this wrong again 😆Yeah, looks generally reasonable. Thanks!

@bors r+

@rust-bors

rust-bors Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 5bd43f3 has been approved by Kobzol

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Sep 8, 2026
@Kobzol

Kobzol commented Sep 8, 2026

Copy link
Copy Markdown
Member

r? kobzol

@rustbot rustbot assigned Kobzol and unassigned wesleywiser Sep 8, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 8, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #157738 (Support move expressions in coroutine closures)
 - #160219 (Implement `Thread::os_id`)
 - #162449 (Prefer removing a redundant shared reference over reborrow)
 - #162494 (Ignore `self-in-const-generics` test for parallel frontend)
 - #162495 (Reserve items in `Extend` implementations)
 - #162238 (trait solver: Include implied outlives assumptions)
 - #162473 (Small `x perf` improvements)
 - #162489 (Clean up on upvar_tys)
 - #162500 (Move the `expect-item-after-attribute.rs` test to the correct directory)
@rust-bors
rust-bors Bot merged commit 31971f0 into rust-lang:main Sep 9, 2026
14 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 9, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 9, 2026
Rollup merge of #162495 - JonathanBrouwer:reserve-mono-extend, r=Kobzol

Reserve items in `Extend` implementations

This might be a perf win, inspired by @Kobzol's approach in this PR: #162480
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants