Interner front caches and sharded capacity fix - #106
Open
xmakro wants to merge 2 commits into
Open
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.
Two changes to the type interners, aimed at the interning + hashbrown cost that profiling shows at ~5-6% of check builds, and at the parallel-mode memory footprint.
Commit 1:
ShardedHashMap::with_capacitynow means total capacity across shards. Previously every one of the 32 shards received the full requested capacity, so with-Zthreads > 1eachCtxtInternerstable allocated 32x its intended size. The dep-graph call site already divided byshards()to compensate; that division moved inside. Serial behavior is bit-identical (single shard, divide by 1). Measured: ~41-43 MB max-rss reduction per rustc process at-Zthreads=8(syn -15%, serde -12%, regex-automata -11%), instructions:u neutral (+0.00% mean over 32 cells).Commit 2: per-worker front caches for the four hottest interners (types, predicates, generic-arg lists, type lists). Interning is dominated by hits on recently-interned values, but each hit probes a large, mostly cache-cold hash table under a shard lock. A 4096-entry direct-mapped array per worker (via
WorkerLocal, like the arena) is checked first using the already-computed Fx hash; hits skip the lock and the probe, misses fall through to the shared interner and fill the slot. TheRefCellborrow is held across the fallback so unexpected reentrance panics rather than corrupting the cache.Measurements (stage2 ThinLTO + jemalloc, Check profile):
-Zthreads=1and=8; regex-automata -8.7%. Wall on this machine is noisy (±3-5% per cell); the instruction counts are the authoritative serial metric.FRONT_CACHE_BITS = 12is untuned; the const and clauses interners are not covered yet and are candidates for a follow-up.