rustc_monomorphize: shard volatile generic CGU buckets to reduce incremental invalidation scope - #162692
rustc_monomorphize: shard volatile generic CGU buckets to reduce incremental invalidation scope#162692Trigodil wants to merge 4 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
…emental invalidation scope
b2d8f24 to
cfca780
Compare
This comment has been minimized.
This comment has been minimized.
|
Let's try this out. @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.
rustc_monomorphize: shard volatile generic CGU buckets to reduce incremental invalidation scope
|
@bors try cancel |
|
Try build cancelled. Cancelled workflows: Hint: if you want to run another try build, you do not need to manually cancel the previous one. Just run |
Got it Co-authored-by: Matyáš Racek <panstromek@seznam.cz>
|
@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.
rustc_monomorphize: shard volatile generic CGU buckets to reduce incremental invalidation scope
This comment has been minimized.
This comment has been minimized.
|
You can ignore tidy for experiments like this, it won't fail the |
Gotcha, its just really annoying for me when one fails |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
It seems that forcing this on unconditionally breaks the tests, since they assert exact CGU names (e.g. local_generic.volatile) and now get a .shard0XX suffix appended everywhere |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (6c4e7b9): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.4%, secondary 2.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 82.8%, secondary 63.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 32.7%, secondary 42.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 497.802s -> 494.017s (-0.76%) |
View all comments
Summary
The current CGU partitioner assigns every monomorphized instance of a generic
function from the same module into a single "volatile" bucket, keyed on
(module_def_id, volatile). This means editing the body of any instantiationinvalidates the entire bucket -- every other instantiation in that module gets
re-emitted on the next incremental build, even ones that share no code with the
change.
This PR adds
-Z fine-grained-generic-cgus, which shards each volatile bucketinto a bounded number of sub-buckets by hashing the instantiation's fully-mangled
symbol name. An edit to one instantiation's code path now only invalidates the
~1/shard_count of instantiations that hash into the same shard.
Approach
Shard count is derived from
-C codegen-units, floored at the host's availableparallelism and clamped to [4, 128]. This keeps the total CGU count in the same
ballpark as a normal build while ensuring the codegen backend always has enough
independent units to keep every core busy.
Unbounded splitting (one CGU per instantiation) was tested first and regresses
heavily on real crates:
merge_codegen_unitsis intentionally skipped inincremental mode, so hundreds of tiny object files pile up with no recombination,
and link cost dominates. Bounded sharding avoids this entirely.
Benchmarks (polars-core, ChunkedArray)
-Z threads=4Tested on
polars-corewhich has high monomorphization volume(
ChunkedArray<T>instantiations survivemerge_codegen_unitsand make thevolatile bucket expensive to invalidate). Methodology uses a body-edit approach
by item content, not file bytes.
Notes
Disclosure
Claude Sonnet 4.6 was used to speed up compiler research and to rule out dead ends in the methodology used.