perf: Index trait impls by their rigid self type [bitmaps -23%, typenum -18%] - #86
Draft
xmakro wants to merge 1 commit into
Draft
perf: Index trait impls by their rigid self type [bitmaps -23%, typenum -18%]#86xmakro wants to merge 1 commit into
xmakro wants to merge 1 commit into
Conversation
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.
for_each_relevant_implnarrows the impls of a trait down by the outermost layer of the selftype. A trait implemented for many instances of one generic type,
impl Bits for BitsImpl<1>through
BitsImpl<1024>say, ends up with all of its impls under one key, so every lookup walksall of them and runs the deep reject on each. On
bitmapsthat is 15.7% of the compile inargs_may_unifyplus 5.3% inimpl_trait_ref.A self type that contains nothing that could still be inferred or normalized unifies only with a
type equal to it up to regions. Impls with such a self type are therefore relevant to lookups of
that one type only, and can be indexed by it. The impls whose self type is not rigid stay in a
list that every lookup considers, and a lookup of a self type that is not itself rigid falls
back to walking the whole entry. The index is only built for keys with at least 16 impls, and it
is left out of the stable hash because it is derived from the list it refines.
The key is a hash of the region-erased type, which is cheap because types are interned and hash
by address.
Measured on 12 crates, Check and Debug,
instructions:u, isolated against the same base:The other 18 cells (cranelift-codegen, clap_derive, hyper, image, many-assoc-items, match-stress,
ripgrep, serde, syn) are all within 0.10%, geomean -3.64%.
The full
tests/uisuite passes (21309 tests), as dotests/incremental(178 tests) and therustc_pattern_analysisunit tests.