Skip to content

Deduplicate DefId encodings in the query cache - #164300

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
TaKO8Ki:dedup-query-cache-defids
Oct 25, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
TaKO8Ki:dedup-query-cache-defids

Conversation

@TaKO8Ki

@TaKO8Ki TaKO8Ki commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

I used a similar approach for DefId encoding and decoding, based on the existing Symbol encoder and decoder.

fn encode_symbol_or_byte_symbol(

fn decode_symbol_or_byte_symbol<S>(

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 14, 2026
@TaKO8Ki

TaKO8Ki commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 14, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 14, 2026
Deduplicate DefId encodings in the query cache
@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 381214b (381214b82df0417c4443eb8d1e89530cdc28c058)
Base parent: 2d37576 (2d37576c3d7134aa2d5c2f2396712a8b4a38ef6f)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (381214b): comparison URL.

Overall result: ❌ regressions - 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 @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.8% [0.1%, 1.5%] 132
Regressions ❌
(secondary)
0.7% [0.1%, 2.1%] 89
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [0.1%, 1.5%] 132

Max RSS (memory usage)

Results (primary -1.7%, secondary -4.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.7% [-2.9%, -1.0%] 29
Improvements ✅
(secondary)
-4.2% [-5.3%, -1.5%] 7
All ❌✅ (primary) -1.7% [-2.9%, -1.0%] 29

Cycles

Results (secondary -1.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.0% [2.0%, 2.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.1% [-4.1%, -4.1%] 1
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 487.613s -> 488.634s (0.21%)
Artifact size: 406.81 MiB -> 406.90 MiB (0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 14, 2026
@TaKO8Ki

TaKO8Ki commented Oct 14, 2026 •

Copy link
Copy Markdown
Member Author

Instruction-count regressions were concentrated in incremental rebuilds, averaging 0.8% in the affected primary cases and 0.7% in the affected secondary cases.

Query-cache size decreased by 25.71% on average across the relevant primary and secondary cases.

image

https://perf.rust-lang.org/compare.html?start=2d37576c3d7134aa2d5c2f2396712a8b4a38ef6f&end=381214b82df0417c4443eb8d1e89530cdc28c058&stat=size%3Aquery_cache&tab=compile

@Kobzol

Kobzol commented Oct 14, 2026

Copy link
Copy Markdown
Member

Nice wins there. I tried building (cargo build) the https://github.com/It4innovations/hyperqueue crate before/after this PR. Size of the target dir:

  • Before: 1527784 B
  • After: 1501924 B

So about a 2% (~25 MiB) reduction here, for a clean incremental build.

@TaKO8Ki
TaKO8Ki marked this pull request as ready for review October 14, 2026 10:02
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 14, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 14, 2026
@rustbot

rustbot commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

r? @beetrees

rustbot has assigned @beetrees.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, query-system
  • compiler, query-system expanded to 77 candidates
  • Random selection from 18 candidates

@panstromek

Copy link
Copy Markdown
Contributor

Most of the icount increase in serde opt incr-unchanged comes from Span encoding and decoding. That seems a bit weird. Is there something unexpected going on? How does this interact with spans?

30,275,316 (100.0%)  PROGRAM TOTALS

--------------------------------------------------------------------------------
-- File:function summary
--------------------------------------------------------------------------------
  Ir________________________  file:function

< 29,982,329 (99.0%,  99.0%)  ???:
  11,173,357 (36.9%)            <rustc_middle::query::on_disk_cache::CacheEncoder as rustc_span::SpanEncoder>::encode_span
   9,874,207 (32.6%)            <rustc_middle::query::on_disk_cache::CacheDecoder as rustc_span::SpanDecoder>::decode_span
   3,952,030 (13.1%)            <rustc_middle::query::on_disk_cache::CacheDecoder as rustc_span::SpanDecoder>::decode_def_id
   3,616,469 (11.9%)            <rustc_middle::query::on_disk_cache::CacheEncoder as rustc_span::SpanEncoder>::encode_def_id
   1,228,968  (4.1%)            <rustc_middle::mir::syntax::Operand as rustc_serialize::serialize::Decodable<rustc_middle::query::on_disk_cache::CacheDecoder>>::decode
    -867,459 (-2.9%)            <rustc_middle::mir::syntax::Place as rustc_serialize::serialize::Decodable<rustc_middle::query::on_disk_cache::CacheDecoder>>::decode
    -861,145 (-2.8%)            <alloc::vec::Vec<rustc_span::Spanned<rustc_middle::mir::syntax::Operand>> as rustc_serialize::serialize::Decodable<rustc_middle::query::on_disk_cache::CacheDecoder>>::decode
     836,200  (2.8%)            <rustc_middle::query::on_disk_cache::CacheDecoder as rustc_span::BlobDecoder>::decode_local_def_id
     704,292  (2.3%)            rustc_query_impl::incremental::encode_query_values_inner::<rustc_middle::query::caches::DefIdCache<rustc_middle::query::erase::ErasedData<[u8; 8]>>, &rustc_middle::ty::generics::Generics>::{closure#0}
     567,527  (1.9%)            <hashbrown::raw::RawTable<(rustc_middle::ty::Ty, usize)>>::reserve_rehash::<hashbrown::map::make_hasher<rustc_middle::ty::Ty, usize, rustc_hash::FxBuildHasher>::{closure#0}>
    -537,260 (-1.8%)            <rustc_stable_hash::sip128::SipHasher128>::finish128_inner

@TaKO8Ki

TaKO8Ki commented Oct 14, 2026 •

Copy link
Copy Markdown
Member Author

@panstromek SpanData contains a parent Option<LocalDefId>, and this change also affects how LocalDefId is encoded and decoded. I think this is contributing to the increased cost of Span encoding and decoding.

span_data.parent.encode(self);

@beetrees

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8190021 has been approved by beetrees

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 5. This pull request will be tested once the tree is reopened.

Reason for tree closure: test-aarch64-apple-macos-26-2 out of disk space

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 25, 2026
@JonathanBrouwer

JonathanBrouwer commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

@bors rollup=iffy
Adding this to a perf-sensitive rollup

rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
…uwer

Rollup of 4 perf-sensitive pull requests

Successful merges:

 - #163845 (Add various `#[inline]` annotations for simple functions on hot paths that don't get inlined)
 - #164122 (Don't emit allow attributes in try/contract desugaring)
 - #164260 (create fast path for attributes created in builtin macro expansions)
 - #164300 (Deduplicate DefId encodings in the query cache)

Failed merges:

 - #164790 (Split `LintLevelsBuilder::add` into `add_ast` and `add_hir`)
rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
…uwer

Rollup of 4 perf-sensitive pull requests

Successful merges:

 - #163845 (Add various `#[inline]` annotations for simple functions on hot paths that don't get inlined)
 - #164122 (Don't emit allow attributes in try/contract desugaring)
 - #164260 (create fast path for attributes created in builtin macro expansions)
 - #164300 (Deduplicate DefId encodings in the query cache)

Failed merges:

 - #164790 (Split `LintLevelsBuilder::add` into `add_ast` and `add_hir`)
rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #163845 (Add various `#[inline]` annotations for simple functions on hot paths that don't get inlined)
 - #164122 (Don't emit allow attributes in try/contract desugaring)
 - #164260 (create fast path for attributes created in builtin macro expansions)
 - #164300 (Deduplicate DefId encodings in the query cache)
 - #164929 (Revert "rustc_codegen_gcc subtree update")

Failed merges:

 - #164790 (Split `LintLevelsBuilder::add` into `add_ast` and `add_hir`)
@rust-bors
rust-bors Bot merged commit 9e7c7bd into rust-lang:main Oct 25, 2026
15 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 25, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
Rollup merge of #164300 - TaKO8Ki:dedup-query-cache-defids, r=beetrees

Deduplicate DefId encodings in the query cache

I used a similar approach for DefId encoding and decoding, based on the existing Symbol encoder and decoder.

https://github.com/rust-lang/rust/blob/81900216ce9ee0b48f2c563c696bfca98cfba755/compiler/rustc_middle/src/query/on_disk_cache.rs#L818

https://github.com/rust-lang/rust/blob/81900216ce9ee0b48f2c563c696bfca98cfba755/compiler/rustc_middle/src/query/on_disk_cache.rs#L447
@rust-timer

Copy link
Copy Markdown
Collaborator

Note

This PR was benchmarked as part of triage of its containing rollup: triage URL.

Finished benchmarking commit (69cf161): comparison URL.

Overall result: ❌ regressions - please read:

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.8% [0.1%, 1.6%] 149
Regressions ❌
(secondary)
0.7% [0.1%, 2.2%] 81
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [0.1%, 1.6%] 149

Max RSS (memory usage)

Results (primary -1.1%, secondary -2.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.9% [0.4%, 1.8%] 10
Regressions ❌
(secondary)
0.8% [0.4%, 1.6%] 4
Improvements ✅
(primary)
-1.7% [-6.5%, -0.5%] 37
Improvements ✅
(secondary)
-3.4% [-5.2%, -0.9%] 10
All ❌✅ (primary) -1.1% [-6.5%, 1.8%] 47

Cycles

Results (primary 0.0%, secondary 0.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.8% [0.5%, 1.2%] 8
Regressions ❌
(secondary)
1.5% [1.0%, 2.4%] 4
Improvements ✅
(primary)
-0.9% [-2.2%, -0.4%] 7
Improvements ✅
(secondary)
-0.6% [-0.7%, -0.5%] 2
All ❌✅ (primary) 0.0% [-2.2%, 1.2%] 15

Binary size

This perf run didn't have relevant results for this metric.

Artifact size: 405.91 MiB -> 405.98 MiB (0.02%)

@panstromek

Copy link
Copy Markdown
Contributor

perf triage:

This impact was known before merge. This PR trades small icount regressions for large query cache size improvements.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants