Skip to content

Avoid Vec allocation in TyCtxt::mk_place_elem#155778

Open
kevinheavey wants to merge 1 commit intorust-lang:mainfrom
kevinheavey:perf-mk-place-elem-avoid-vec-alloc
Open

Avoid Vec allocation in TyCtxt::mk_place_elem#155778
kevinheavey wants to merge 1 commit intorust-lang:mainfrom
kevinheavey:perf-mk-place-elem-avoid-vec-alloc

Conversation

@kevinheavey
Copy link
Copy Markdown

mk_place_elem appends a single PlaceElem to an existing (interned) projection. The current implementation copies the projection into a fresh Vec, pushes the new element, and re-interns the slice, which allocates on every call.

Feed the elements through mk_place_elems_from_iter so that CollectAndApply's hand-unrolled stack fast path (up to 9 elements, in rustc_type_ir::interner) kicks in for the common case of short projections and the Vec allocation is skipped entirely. The behavior is identical for longer projections (the fast path falls back to a Vec internally).

`mk_place_elem` appends a single `PlaceElem` to an existing (interned)
projection. The current implementation copies the projection into a
fresh `Vec`, pushes the new element, and re-interns the slice, which
allocates on the heap on every call.

Feed the elements through `mk_place_elems_from_iter` so that
`CollectAndApply`'s hand-unrolled stack fast path (up to 9 elements,
in `rustc_type_ir::interner`) kicks in for the common case of short
projections and the `Vec` allocation is skipped entirely. The behavior
is identical for longer projections (the fast path falls back to a
`Vec` internally).
@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 Apr 25, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 25, 2026

r? @JohnTitor

rustbot has assigned @JohnTitor.
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, types
  • compiler, types expanded to 73 candidates
  • Random selection from 20 candidates

@cjgillot
Copy link
Copy Markdown
Contributor

Seems reasonable, let's see what perf says.

@bors try @rust-timer queue

@rust-timer
Copy link
Copy Markdown
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 26, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 26, 2026

⌛ Trying commit 5cd9d92 with merge 7a0916d

To cancel the try build, run the command @bors try cancel.

Workflow: https://github.com/rust-lang/rust/actions/runs/24960896151

rust-bors Bot pushed a commit that referenced this pull request Apr 26, 2026
…c, r=<try>

Avoid Vec allocation in TyCtxt::mk_place_elem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-perf Status: Waiting on a perf run to be completed. 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.

5 participants