Skip to content

Use repeat_n in Vec::extend_with#155928

Open
DaniPopes wants to merge 1 commit intorust-lang:mainfrom
DaniPopes:vec-spec-extend-with
Open

Use repeat_n in Vec::extend_with#155928
DaniPopes wants to merge 1 commit intorust-lang:mainfrom
DaniPopes:vec-spec-extend-with

Conversation

@DaniPopes
Copy link
Copy Markdown
Contributor

Simplify Vec::extend_with to use extend(repeat_n(...)). This delegates to extend_trusted which essentially does the same thing but using a single loop; the "don't clone the last element" logic is handled inside of the repeat_n iterator.

This generates slightly better code by removing the manual store of the last element: https://godbolt.org/z/TG6GPY9Eh

@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 Apr 28, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 28, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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: libs
  • libs expanded to 7 candidates
  • Random selection from Mark-Simulacrum, jhpratt, nia-e

@rust-log-analyzer

This comment has been minimized.

@DaniPopes DaniPopes force-pushed the vec-spec-extend-with branch from 4361e93 to 88833cf Compare April 28, 2026 14:57
@scottmcm
Copy link
Copy Markdown
Member

scottmcm commented May 1, 2026

r? scottmcm
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot assigned scottmcm and unassigned Mark-Simulacrum May 1, 2026
@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 May 1, 2026
rust-bors Bot pushed a commit that referenced this pull request May 1, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 1, 2026

☀️ Try build successful (CI)
Build commit: 4ac3534 (4ac3534e21548421df6f6113981f3b65a1477e1a, parent: 0164cc139285d5452053bcc5a83da046a501ed61)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (4ac3534): 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
@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.6% [0.1%, 19.4%] 81
Regressions ❌
(secondary)
0.3% [0.2%, 0.7%] 39
Improvements ✅
(primary)
-1.7% [-1.7%, -1.7%] 1
Improvements ✅
(secondary)
-0.6% [-0.7%, -0.6%] 6
All ❌✅ (primary) 0.5% [-1.7%, 19.4%] 82

Max RSS (memory usage)

Results (primary 0.1%, secondary -0.3%)

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

mean range count
Regressions ❌
(primary)
3.0% [2.4%, 3.5%] 2
Regressions ❌
(secondary)
0.6% [0.5%, 0.7%] 2
Improvements ✅
(primary)
-2.8% [-3.8%, -1.9%] 2
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) 0.1% [-3.8%, 3.5%] 4

Cycles

Results (primary 12.6%, secondary -1.4%)

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

mean range count
Regressions ❌
(primary)
12.6% [6.5%, 18.6%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.4% [-2.3%, -0.6%] 2
All ❌✅ (primary) 12.6% [6.5%, 18.6%] 2

Binary size

Results (primary 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.7% [0.1%, 1.8%] 33
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.7% [-0.0%, 1.8%] 36

Bootstrap: 482.686s -> 483.185s (0.10%)
Artifact size: 390.94 MiB -> 390.90 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 May 1, 2026
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-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.

6 participants