Skip to content

Avoid an intermediate vec when ref-decoding to &'tcx [T] - #162350

Closed
Zalathar wants to merge 1 commit into
rust-lang:mainfrom
Zalathar:ref-decode-slice
Closed

Avoid an intermediate vec when ref-decoding to &'tcx [T]#162350
Zalathar wants to merge 1 commit into
rust-lang:mainfrom
Zalathar:ref-decode-slice

Conversation

@Zalathar

@Zalathar Zalathar commented Sep 6, 2026

Copy link
Copy Markdown
Member

For !needs_drop types, this should allow decoding directly into the arena-allocated slice.

For needs_drop types, the arena already collects into a SmallVec, so this avoids an intermediate conversion from Vec to SmallVec.


I was planning some cleanups to RefDecodable impls (#162287), and along the way I noticed that some hand-written impls for slices manage to avoid the overhead of decoding to an intermediate Vec, by instead reading a usize length and then decoding that many items directly. This matches the format that encoding a vec/slice or decoding to Vec would use.

This PR therefore applies that same optimization to the impls generated by impl_ref_decodable_into_arena!.

I extracted this change into its own small PR since it has perf effects.

r? nnethercote (or compiler)

For !needs_drop types, this should allow decoding directly into the
arena-allocated slice.

For needs_drop types, the arena already collects into a SmallVec<T>, so this
avoids an intermediate conversion from Vec<T> to SmallVec<T>.
@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 Sep 6, 2026
@Zalathar

Zalathar commented Sep 6, 2026

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

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 6, 2026
Avoid an intermediate vec when ref-decoding to `&'tcx [T]`
@rust-bors

rust-bors Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 629cf3b (629cf3bf6d1771b98aa38784f53c8969e5187bb4)
Base parent: f248f40 (f248f4038796913873f11ca65b1b901e311c8dae)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (629cf3b): comparison URL.

Overall result: no relevant changes - 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

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

Max RSS (memory usage)

Results (secondary 7.4%)

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

Cycles

Results (secondary 3.9%)

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

Binary size

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

Bootstrap: 476.686s -> 477.652s (0.20%)
Artifact size: 403.40 MiB -> 403.46 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 6, 2026
@Zalathar

Zalathar commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

Hmm, curious that this on its own didn't produce any measurable perf effect.

@Zalathar

Zalathar commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

Based on another perf run of #162287, the changes I saw were noise, so I’ll close this PR and keep it as part of the larger cleanup PR.

@Zalathar Zalathar closed this Sep 6, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 6, 2026
@Zalathar
Zalathar deleted the ref-decode-slice branch September 6, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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