Skip to content

Remap def indices for deterministic metadata encoding - #162809

Draft
aerooneqq wants to merge 12 commits into
rust-lang:mainfrom
aerooneqq:def-index-remapping
Draft

aerooneqq wants to merge 12 commits into
rust-lang:mainfrom
aerooneqq:def-index-remapping

Conversation

@aerooneqq

@aerooneqq aerooneqq commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

View all comments

Now at the very early stage (however fixes corresponding issues), draft primarily for CI.

cc #t-compiler/const-eval > DefId reproducibility with the parallel frontend

r? @petrochenkov

@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 Sep 15, 2026
@aerooneqq aerooneqq changed the title Remap def indices for deterministic metadata encoing Remap def indices for deterministic metadata encoding Sep 15, 2026
@susitsm

susitsm commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Are the changes in decoder.rs and def_path_hash_map.rs needed? It seems unrelated to me.

@aerooneqq

Copy link
Copy Markdown
Contributor Author

Are the changes in decoder.rs and def_path_hash_map.rs needed? It seems unrelated to me.

We need to update map from hashes to def indices while encoding DefPathHashMap, now I inserted simple FxHashMap to test the approach, if I don't remove functions from decoder.rs there will be warnings, because they are not used anywhere else.

@petrochenkov

Copy link
Copy Markdown
Contributor

@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 Sep 16, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 16, 2026
Remap def indices for deterministic metadata encoding
@rust-bors

rust-bors Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: ceb9839 (ceb98398abf30a57ca7f186c152d2adda7b079f9)
Base parent: 28e8a8c (28e8a8c81bf3b37909edac6c2a76e56f30cd492f)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (ceb9839): 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)
4.4% [0.1%, 164.6%] 276
Regressions ❌
(secondary)
11.8% [0.2%, 130.1%] 350
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.4% [0.1%, 164.6%] 276

Max RSS (memory usage)

Results (primary 3.0%, secondary 4.5%)

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

mean range count
Regressions ❌
(primary)
3.0% [0.8%, 9.4%] 203
Regressions ❌
(secondary)
4.6% [0.9%, 14.8%] 327
Improvements ✅
(primary)
-2.3% [-2.3%, -2.3%] 1
Improvements ✅
(secondary)
-3.6% [-4.0%, -2.9%] 3
All ❌✅ (primary) 3.0% [-2.3%, 9.4%] 204

Cycles

Results (primary 10.2%, secondary 14.6%)

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

mean range count
Regressions ❌
(primary)
10.2% [1.7%, 73.0%] 55
Regressions ❌
(secondary)
14.6% [1.4%, 66.2%] 179
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 10.2% [1.7%, 73.0%] 55

Binary size

Results (primary -0.4%, secondary -0.4%)

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)
-0.4% [-0.4%, -0.3%] 8
Improvements ✅
(secondary)
-0.4% [-0.4%, -0.4%] 4
All ❌✅ (primary) -0.4% [-0.4%, -0.3%] 8

Bootstrap: 496.137s -> 496.27s (0.03%)
Artifact size: 406.79 MiB -> 406.77 MiB (-0.01%)

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

Copy link
Copy Markdown
Contributor

@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 Sep 16, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 16, 2026
Remap def indices for deterministic metadata encoding

#[inline]
fn map_index(&self, index: DefIndex) -> DefIndex {
self.def_indexes_remapping.get(&index).copied().unwrap_or(index)

@susitsm susitsm Sep 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be donewith a vec for better performance. Since we know that these indices are dense in a range. Either a full IndexVec mapping every LocalDefId, or a shorter Vec, that only contains the remapped ones, indexed by remapped_index - min_remapped_index

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is very strong assumption that def ids that are needed to be remapped will be in the end, now it should be true, because resolution and AST -> HIR lowering is executed without any parallelism, however AST -> HIR lowering became more incremental recently by introducing lower_to_hir query which is very easy to parallelize in the beginning of the run_required_analysis function (now it is executed sequentially as we prefetch hir_crate_items which is a sequential HIR visit). If it is parallelized then from each lower_to_hir execution we may invoke arbitrary code that can allocate def ids that do not need to be remapped.

But I like the idea, I was thinking about something similar in a bit different direction: create separate IndexVecs in Definitions struct for different stages of compilation, thus we can maybe pre-allocate and remap ids only for selected parts.

I think that it is reasonable to track the last def id that is allocated during resolution stage, because it is not likely to get parallelized in the nearest time (I hope so) and then to remap all def ids that are allocated after it, I will try it tomorrow.

let mut to_remap = vec![];
let mut def_ids = vec![];
for idx in 0..defs.num_definitions() {
let def_id = LocalDefId { local_def_index: idx.into() };

@susitsm susitsm Sep 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could iterate backwards, stopping when it hits an index not needing remapping. Remapped indices should be at the end

View changes since the review

@rust-bors

rust-bors Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 8bcd37a (8bcd37a7bc50acb44dc7181f601e93127ebf19af)
Base parent: 28e8a8c (28e8a8c81bf3b37909edac6c2a76e56f30cd492f)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (8bcd37a): comparison URL.

Overall result: ❌ regressions - BENCHMARK(S) FAILED

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

❗ ❗ ❗ ❗ ❗
Warning ⚠️: The following benchmark(s) failed to build:

  • Job failure
  • cranelift-codegen-0.119.0

❗ ❗ ❗ ❗ ❗

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.3% [0.1%, 0.6%] 60
Regressions ❌
(secondary)
0.2% [0.1%, 0.3%] 13
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.1%, 0.6%] 60

Max RSS (memory usage)

Results (secondary -4.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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.1% [-5.1%, -3.3%] 3
All ❌✅ (primary) - - 0

Cycles

Results (secondary -0.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)
4.6% [4.6%, 4.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.5% [-2.7%, -2.3%] 2
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 496.137s -> 495.635s (-0.10%)
Artifact size: 406.79 MiB -> 406.74 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 16, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

@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 Sep 17, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 17, 2026
Remap def indices for deterministic metadata encoding
@rust-bors

rust-bors Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 501ad34 (501ad34e355f975a1f1d71121c6738cf001435d7)
Base parent: c999cef (c999cef531ea9059e189e82fe0e82c5daf249bc9)

@rust-timer

This comment has been minimized.

@petrochenkov

Copy link
Copy Markdown
Contributor

r? @oli-obk for example (so I'm not the only one who reviews @aerooneqq's PRs)

@rustbot rustbot assigned oli-obk and unassigned petrochenkov Sep 17, 2026
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (501ad34): comparison URL.

Overall result: ✅ improvements - no action needed

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.

@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
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.1%] 8
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -2.3%, secondary 0.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)
3.4% [3.1%, 3.7%] 2
Improvements ✅
(primary)
-2.3% [-2.3%, -2.3%] 1
Improvements ✅
(secondary)
-2.0% [-3.3%, -0.4%] 3
All ❌✅ (primary) -2.3% [-2.3%, -2.3%] 1

Cycles

Results (primary 4.4%, secondary 4.3%)

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

mean range count
Regressions ❌
(primary)
4.4% [2.4%, 6.4%] 2
Regressions ❌
(secondary)
4.3% [4.3%, 4.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.4% [2.4%, 6.4%] 2

Binary size

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

Bootstrap: 500.132s -> 498.753s (-0.28%)
Artifact size: 406.81 MiB -> 408.93 MiB (0.52%)

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Sep 17, 2026
@rust-bors

rust-bors Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #162920) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants