Avoid Vec allocation in TyCtxt::mk_place_elem#155778
Open
kevinheavey wants to merge 1 commit intorust-lang:mainfrom
Open
Avoid Vec allocation in TyCtxt::mk_place_elem#155778kevinheavey wants to merge 1 commit intorust-lang:mainfrom
kevinheavey wants to merge 1 commit intorust-lang:mainfrom
Conversation
`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).
Collaborator
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Contributor
|
Seems reasonable, let's see what perf says. @bors try @rust-timer queue |
Collaborator
|
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
Contributor
|
⌛ Trying commit 5cd9d92 with merge 7a0916d… To cancel the try build, run the command 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mk_place_elemappends a singlePlaceElemto an existing (interned) projection. The current implementation copies the projection into a freshVec, pushes the new element, and re-interns the slice, which allocates on every call.Feed the elements through
mk_place_elems_from_iterso thatCollectAndApply's hand-unrolled stack fast path (up to 9 elements, inrustc_type_ir::interner) kicks in for the common case of short projections and theVecallocation is skipped entirely. The behavior is identical for longer projections (the fast path falls back to aVecinternally).