Avoid Vec allocation in TyCtxt::mk_place_elem#155778
Avoid Vec allocation in TyCtxt::mk_place_elem#155778rust-bors[bot] merged 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).
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Seems reasonable, let's see what perf says. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…c, r=<try> Avoid Vec allocation in TyCtxt::mk_place_elem
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (7a0916d): comparison URL. Overall result: no relevant changes - no action neededBenchmarking 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 countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)Results (primary 0.4%, secondary -1.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -4.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.0%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 488.641s -> 488.25s (-0.08%) |
|
@bors r+ |
|
@bors r- |
|
This pull request was unapproved. |
|
@bors r=cjgillot,JohnTitor |
Rollup of 12 pull requests Successful merges: - #149624 (Fix requires_lto targets needing lto set in cargo) - #155317 (`std::io::Take`: Clarify & optimize `BorrowedBuf::set_init` usage.) - #155579 (Make Rcs and Arcs use pointer comparison for unsized types) - #155588 (Implement more traits for FRTs) - #155708 (Fix heap overflow in slice::join caused by misbehaving Borrow) - #155778 (Avoid Vec allocation in TyCtxt::mk_place_elem) - #151014 (std: sys: process: uefi: Add program searching) - #155682 (Add boxing suggestions for `impl Trait` return type mismatches) - #155770 (Avoid misleading closure return type note) - #155818 (Convert attribute `FinalizeFn` to fn pointer) - #155829 (rustc_attr_parsing: use a `try {}` in `or_malformed`) - #155835 (couple of `crate_name` cleanups)
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).