Skip to content

Rewrite rustc_span::symbol::Interner to reduce lock contention#157701

Open
heinwol wants to merge 1 commit into
rust-lang:mainfrom
heinwol:symbol-Interner-lock-new
Open

Rewrite rustc_span::symbol::Interner to reduce lock contention#157701
heinwol wants to merge 1 commit into
rust-lang:mainfrom
heinwol:symbol-Interner-lock-new

Conversation

@heinwol

@heinwol heinwol commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

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

Based on #157252

r? @petrochenkov
could you run the CI benches please?

@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 10, 2026
{
Entry::Occupied(v) => v.get().1,
Entry::Vacant(view) => {
let arena_write_lock = self.arena.lock();

@bjorn3 bjorn3 Jun 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The arena can be stored behind the same lock as the map, right? The arena will only be locked while the map is write locked.

View changes since the review

@heinwol heinwol Jun 11, 2026

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.

unfortunately, RwLock<T> Requires T: Sync, which DroplessArena is not

EDIT: hold on, i'm a bit lost here, rechecking

@petrochenkov

Copy link
Copy Markdown
Contributor

I'll run the single-threaded benchmarks after #157701 (comment) is addressed.

In the meantime, @heinwol could you run the parallel benchmarks locally using the https://github.com/Zoxc/rcb tool?
@zetanumbers can explain how to use it.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 10, 2026
@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@heinwol heinwol force-pushed the symbol-Interner-lock-new branch from 3742d99 to d311ef7 Compare June 11, 2026 10:18
@rustbot

rustbot commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

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 heinwol force-pushed the symbol-Interner-lock-new branch from d311ef7 to d51f1b7 Compare June 11, 2026 10:21
@petrochenkov

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 11, 2026
rust-bors Bot pushed a commit that referenced this pull request Jun 11, 2026
Rewrite `rustc_span::symbol::Interner` to reduce lock contention
@heinwol

heinwol commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

There's a question, however: RwLock i use is -- as i found out today -- essentially parking_lot::RwLock. Which forbids us from using a pure sync version in case of sequential computations. Like it's done in Lock itself, that is. Whether it imposes a performance regression is an open question for me...

pub(crate) struct Interner(Lock<InternerInner>);
pub(crate) struct Interner {
map: RwLock<InternerMap>,
arena: Lock<DroplessArena>,

@zetanumbers zetanumbers Jun 11, 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.

It shouldn't be very hard to add an AtomicDroplessArena. Actually there's the VecCache from rustc_data_structures that functions almost exactly like it.

View changes since the review

@rust-bors

rust-bors Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 4b2184e (4b2184eed5371b1852d0ff66a4d231d381a361a0, parent: 485ec3fbcc12fa14ef6596dabb125ad710499c9e)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (4b2184e): 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
@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.3% [0.2%, 0.4%] 9
Regressions ❌
(secondary)
0.4% [0.1%, 2.2%] 41
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.2%, 0.4%] 9

Max RSS (memory usage)

Results (primary -3.0%, secondary -0.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.4% [1.9%, 3.2%] 4
Improvements ✅
(primary)
-3.0% [-3.0%, -3.0%] 1
Improvements ✅
(secondary)
-3.4% [-5.0%, -1.6%] 3
All ❌✅ (primary) -3.0% [-3.0%, -3.0%] 1

Cycles

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)
7.7% [3.3%, 11.2%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.4% [-6.3%, -3.4%] 3
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 517.006s -> 516.711s (-0.06%)
Artifact size: 401.43 MiB -> 402.96 MiB (0.38%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 11, 2026
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-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