Skip to content

Rewrite rustc_span::symbol::Interner to avoid double hashing#157252

Open
heinwol wants to merge 2 commits into
rust-lang:mainfrom
heinwol:symbol-Interner-double-hashing
Open

Rewrite rustc_span::symbol::Interner to avoid double hashing#157252
heinwol wants to merge 2 commits into
rust-lang:mainfrom
heinwol:symbol-Interner-double-hashing

Conversation

@heinwol
Copy link
Copy Markdown

@heinwol heinwol commented Jun 1, 2026

Involves resorting to raw HashTable and writing an ad-hoc IndexMap-like structure, as we cannot get access to raw hashes otherwise.

My local cachegrind profile shows ~ -20_000_000 Ir

r? @petrochenkov

Involves resorting to raw `HashTable` and writing an ad-hoc
`IndexMap`-like structure, as we cannot get access to raw hashes
otherwise.

My local cachegrind profile shows ~ -20_000_000 Ir
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 1, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 1, 2026

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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 Jun 1, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 1, 2026
Rewrite `rustc_span::symbol::Interner` to avoid double hashing
@petrochenkov petrochenkov removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 1, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 1, 2026

☀️ Try build successful (CI)
Build commit: e66b004 (e66b0048988e203053f928d27053451bfb56886a, parent: 4804ad7e93e1b31f4605b7083871d0d3d85a2afe)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (e66b004): 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 @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
@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.8% [0.2%, 1.5%] 5
Improvements ✅
(primary)
-0.6% [-0.8%, -0.2%] 6
Improvements ✅
(secondary)
-0.4% [-2.1%, -0.0%] 36
All ❌✅ (primary) -0.6% [-0.8%, -0.2%] 6

Max RSS (memory usage)

Results (primary 1.6%, secondary 1.2%)

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

mean range count
Regressions ❌
(primary)
1.6% [1.2%, 2.2%] 4
Regressions ❌
(secondary)
4.0% [1.1%, 10.0%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-8.1%, -0.6%] 7
All ❌✅ (primary) 1.6% [1.2%, 2.2%] 4

Cycles

Results (secondary -2.7%)

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)
1.9% [1.9%, 1.9%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-6.3%, -1.6%] 7
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 509.892s -> 512.954s (0.60%)
Artifact size: 400.78 MiB -> 400.82 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 Jun 1, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

The red numbers in include-blob are a noise from LLVM codegen.

@petrochenkov petrochenkov added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 1, 2026
The original implementation used a single
`rustc_data_structures::sync::lock::Lock` for both reads and writes,
which _allegedly_ caused unnecessary lock contention for read-heavy
highly-parallelized scenarios. Now we have 2 locks: `RwLock` for the
symbol map and `Lock` for the arena
@heinwol
Copy link
Copy Markdown
Author

heinwol commented Jun 2, 2026

I've added locking enhancements to reduce contention, maybe this will cause some improvement (or maybe the contrary). Of course, this is only relevant in multithreaded benches, i'm not sure if we can reliably test this.

Also, due to my lack of experience, I'd like a more professional look at whether I have some concurrency bugs. I think I've mitigated the TOCTOU and locking order is deterministic. My benches and tests run fine.

@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

A job failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

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

Labels

perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

5 participants