Avoid repeated lang-item map lookups in sizedness_fast_path [cachegrind -0.22% serde check, suite below local noise] - #67
Draft
xmakro wants to merge 1 commit into
Draft
Conversation
xmakro
force-pushed
the
perf/sizedness-langitem-lookup
branch
from
August 4, 2026 06:01
5384cc5 to
f8c5549
Compare
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.
sizedness_fast_pathruns for a large share of all predicates and paid a reverse-hashmap lookup, hashing theDefId, just to tellSizedfromMetaSized.This resolves the lang-item table once and compares
DefIds directly. Thecaller_boundsloop below reuses the resolvedSizedDefIdinstead of callingtcx.is_lang_itemper bound; cachegrind puts that probe at about 1% of the saved instructions, so the loop change is a consistency cleanup and the win is the head lookup.LanguageItems::getgets#[inline]so the accessor is an array index rather than an out-of-line cross-crate call. Without it, a non-LTO build would add a call on the miss path instead of removing work.The comparison is equivalent to the old one because each lang item resolves to at most one
DefIdand eachDefIdto at most one lang item:LanguageItems::setis the only writer of both tables, and duplicate#[lang]items abort before this code can run.Cachegrind on serde check full attributes the effect cleanly: -18.6M instructions (-0.22%), all of it in
as_lang_itemand the reverseIndexMaplookup it wraps, with the rest of the compiler contributing 1.5K instructions of the 18.6M.Suite-level instruction counts cannot resolve a change this small locally: the 15-cell geomean (5 crates x check/debug/opt, full, jemalloc) reads -0.18% against one clean-base build and +0.07% against a second build of the same base commit, because same-commit stage2 rebuilds differ by 0.25% geomean (up to 0.7% on single cells). Serde is the only crate that stays improved against both base builds in all three profiles, consistent with the cachegrind number. The suite-level verdict needs a rust-timer run.