# Patched rustc to fix why editing one generic method recompiles all 200 instantiations

**URL:** <https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595>\
**Category:** compiler\
**Created:** [September 12, 2026, 7:20am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595 "2026-09-12T07:20:40Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trigodil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/trigodil/32/14566_2.png) [@Trigodil](https://internals.rust-lang.org/u/Trigodil)\
**Post date:** [September 12, 2026, 7:20am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/1 "2026-09-12T07:20:40Z")

</div>

So I was getting annoyed by slow incremental builds and ended up digging into `rustc_monomorphize::partitioning` in the compiler . Found something interesting - every monomorphization of a generic function gets pooled into one volatile CGU keyed on `(module_def_id, volatile)`, type args completely ignored. So if you touch one method body in a generic-heavy crate, every single instantiation gets re-emitted. All of em. Even ones that have nothing to do with your change.

Wrote a patch that shards the volatile bucket by `hash(symbol) % shard_count` instead. One edit now only invalidates ~N/shard\_count instantiations. Benchmarked on polars core, got ~0.96× incremental. Also stumbled on the fact that just setting `-C codegen-units=16` (vs polars-core's default of 256) beat that result on its own, which I did not expect at all

Also tried one CGU per instantiation - that was 20× slower incremental because `merge_codegen_units` gets skipped in incremental mode. So it seems like bounded sharding is the move.

Benchmarked on polars-core. Patch alone: ~1% faster incremental. Full stack (patch + `-Z threads=4` + cranelift + `-C codegen-units=16`) **0.521× cold** , roughly 1.9× faster than baseline.

| Configuration | Cold | | Ratio |
| --- | --- | --- | --- |
| No Flag Baseline | 62.27s | | 1x |
| Hashsharded patch | 54.01s | | 0.868× |
| -Z threads=4 | 40.38s | | 0.739× |
| patch + threads4 (cu=256) | 36.54s | | 0.587× |
| Cranelift (in-tree) | 58.03s | | 0.932× |
| patch + threads4 + cranelift (cu=256) | 38.20s | | 0.613× |
| patch + threads4 (cu=16) | 33.77s | | 0.542× |
| patch + threads4 + cranelift (cu=16) | 32.45s | | 0.521× |

```rust
Note that the following test was done in an Intel Xeon with 4 cores and 15 GB available Ram

```

Patch adds `-Z fine-grained-generic-cgus`.

I thought this was interesting and wanted to share it

Blog post: [I patched the Rust compiler because the build times were annoying me](https://trigodil.github.io/blog/rust-compiler-build-times.html) Patch and benchmarks: [GitHub - Trigodil/Rust: A repo for compiler research for Rust · GitHub](https://github.com/Trigodil/Rust)

---

<div class="post-metadata">

**Author:** ![pacak](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pacak/32/11934_2.png) [@pacak](https://internals.rust-lang.org/u/pacak)\
**Post date:** [September 12, 2026, 11:01am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/2 "2026-09-12T11:01:02Z")

</div>

"Column 1", "Column 2", "Column 3"?

---

<div class="post-metadata">

**Author:** ![Trigodil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/trigodil/32/14566_2.png) [@Trigodil](https://internals.rust-lang.org/u/Trigodil)\
**Post date:** [September 12, 2026, 11:04am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/3 "2026-09-12T11:04:04Z")

</div>

Apologies! fixed it

---

<div class="post-metadata">

**Author:** ![pacak](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pacak/32/11934_2.png) [@pacak](https://internals.rust-lang.org/u/pacak)\
**Post date:** [September 12, 2026, 11:23am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/4 "2026-09-12T11:23:07Z")

</div>

> [@Trigodil](#):
>
> Benchmarked on polars-core. Patch alone: ~1% faster incremental.

that's within the noise I think. Why all of this instead of making a pull request?

---

<div class="post-metadata">

**Author:** ![jdahlstrom](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jdahlstrom/32/3351_2.png) [@jdahlstrom](https://internals.rust-lang.org/u/jdahlstrom)\
**Post date:** [September 12, 2026, 11:25am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/5 "2026-09-12T11:25:07Z")

</div>

> [@Trigodil](#):
>
> 54.01s 0.988×

Surely 54/62 \< 0.988?

---

<div class="post-metadata">

**Author:** ![matthieum](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/matthieum/32/4023_2.png) [@matthieum](https://internals.rust-lang.org/u/matthieum)\
**Post date:** [September 12, 2026, 11:25am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/6 "2026-09-12T11:25:38Z")

</div>

Within the noise on incremental but 50% faster on from-scratch is actually pretty good, no?

---

<div class="post-metadata">

**Author:** ![pacak](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pacak/32/11934_2.png) [@pacak](https://internals.rust-lang.org/u/pacak)\
**Post date:** [September 12, 2026, 11:33am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/7 "2026-09-12T11:33:25Z")

</div>

Overall - would be good, but here I see it in one very cherry picked scenario with changed flags and non default codegen.

---

<div class="post-metadata">

**Author:** ![Trigodil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/trigodil/32/14566_2.png) [@Trigodil](https://internals.rust-lang.org/u/Trigodil)\
**Post date:** [September 12, 2026, 11:41am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/8 "2026-09-12T11:41:56Z")

</div>

It scales with how many monomorphizations you have - smaller crates won't show it because the volatile bucket stays small. polars core is a stress test, picked it because I was informed it was the hardest case.

---

<div class="post-metadata">

**Author:** ![Trigodil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/trigodil/32/14566_2.png) [@Trigodil](https://internals.rust-lang.org/u/Trigodil)\
**Post date:** [September 12, 2026, 11:44am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/9 "2026-09-12T11:44:14Z")

</div>

Yep, pretty much. The incremental is smaller but it compounds on every edit in a large generic heavy crate.

---

<div class="post-metadata">

**Author:** ![Trigodil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/trigodil/32/14566_2.png) [@Trigodil](https://internals.rust-lang.org/u/Trigodil)\
**Post date:** [September 12, 2026, 11:46am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/10 "2026-09-12T11:46:44Z")

</div>

Fixed it

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [September 12, 2026, 5:15pm UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/11 "2026-09-12T17:15:27Z")

</div>

I'm puzzled why you're posting here instead of making a PR. Was this vibe-coded and thus against the LLM policy or something?

---

<div class="post-metadata">

**Author:** ![pacak](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pacak/32/11934_2.png) [@pacak](https://internals.rust-lang.org/u/pacak)\
**Post date:** [September 12, 2026, 10:23pm UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/12 "2026-09-12T22:23:42Z")

</div>

This post was flagged by the community and is temporarily hidden.

---

<div class="post-metadata">

**Author:** ![Trigodil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/trigodil/32/14566_2.png) [@Trigodil](https://internals.rust-lang.org/u/Trigodil)\
**Post date:** [September 13, 2026, 7:18am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/13 "2026-09-13T07:18:19Z")

</div>

I have already created a PR concerning this fix, a separate repo was created for testing my own methodology and my notes of Rust compiler code to be thorough, although I will say because of the accusations of "AI" makes it un-preferable for me to contribute to the rust community further.

---

<div class="post-metadata">

**Author:** ![Vorpal](https://avatars.discourse-cdn.com/v4/letter/v/aca169/32.png) [@Vorpal](https://internals.rust-lang.org/u/Vorpal)\
**Post date:** [September 13, 2026, 7:46pm UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/14 "2026-09-13T19:46:34Z")

</div>

> [@Trigodil](#):
>
> accusations of "AI" makes it un-preferable for me to contribute to the rust community further.

The rust community somewhat recently adopted an [AI policy](https://forge.rust-lang.org/policies/llm-usage.html) that allows AI for some cases (such as researching what to change) but is more restrictive (but not outright banning, depending on details) for the actual submitted content of the contributions themselves.

It appears that people are a bit unsure about what you used LLMs for and to what degree and are thus trying to figure that out. So I think the word "accusations" might be a bit strong at this point, "questioning" and "inquiry" might be more appropriate at this point.

---

<div class="post-metadata">

**Author:** ![DanielFath](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/danielfath/32/5372_2.png) [@DanielFath](https://internals.rust-lang.org/u/DanielFath)\
**Post date:** [September 13, 2026, 9:15pm UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/15 "2026-09-13T21:15:51Z")

</div>

The question makes sense. Why is this an internals post, when it could just be a Github PR?

Rust isn't against LLMs per se, but they can't be used to write code/comments/PR descripitons. It's a decent compromise seeing how LLM code might not be copyrightable, and thus accepting such code into codebase is a liability, and LLMs tend to overexplain to the nth degree.

---

<div class="post-metadata">

**Author:** ![Kobzol](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kobzol/32/8433_2.png) [@Kobzol](https://internals.rust-lang.org/u/Kobzol)\
**Post date:** [September 14, 2026, 7:03am UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/17 "2026-09-14T07:03:03Z")

</div>

A PR was actually opened to test this change. Here are the out-of-the-box perf. results on our benchmark suite: [rustc\_monomorphize: shard volatile generic CGU buckets to reduce incremental invalidation scope by Trigodil · Pull Request #162692 · rust-lang/rust · GitHub](https://github.com/rust-lang/rust/pull/162692#issuecomment-5648149009)

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [September 14, 2026, 3:36pm UTC](https://internals.rust-lang.org/t/patched-rustc-to-fix-why-editing-one-generic-method-recompiles-all-200-instantiations/24595/18 "2026-09-14T15:36:56Z")

</div>

> [@Trigodil](#):
>
> although I will say because of the accusations of "AI" makes it un-preferable for me to contribute to the rust community further.

I didn't even look at the change. It's just the only obvious reason to post on IRLO about it: if it's an amazing PR that's getting merged I figured you'd have linked that PR, so if it's not a PR the most typical reason these days is that it doesn't meet the PR bar because of LLM usage.

It gives me the same kind of vibes as the Bun blog posts complaining about Zig not taking their PRs 🤷

(Plus the blog credits claude and has a bunch of classic LLM-style phrasings so it's hardly unsurprising that people might wonder if there was "AI" usage.)
