Skip to content

Backport WorkerLocal#155649

Open
zetanumbers wants to merge 3 commits intorust-lang:mainfrom
zetanumbers:worker_local
Open

Backport WorkerLocal#155649
zetanumbers wants to merge 3 commits intorust-lang:mainfrom
zetanumbers:worker_local

Conversation

@zetanumbers
Copy link
Copy Markdown
Contributor

@zetanumbers zetanumbers commented Apr 22, 2026

#107782 added a WorkerLocal into rustc_data_structures. Due to it being ported from the old rustc rayon fork it required also porting Registry and sort of hack it in there. This PR replaces new version with the old one while trying to backport whatever microoptimizations were added. But I doubt #107782's manual benchmarks as those aren't significantly big to differentiate from the noise, although that's from my experience.

One difference I haven't yet addressed is an indirection through thread-local WORKER_THREAD_STATE pointer. I've found that changing its type to ManuallyDrop<OnceCell<WorkerThread>> itself is essentially a clean up/refactor which I've stashed for now.

cc @Zoxc

@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 Apr 22, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 22, 2026

r? @nikomatsakis

rustbot has assigned @nikomatsakis.
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
  • compiler expanded to 72 candidates
  • Random selection from 17 candidates

@Zoxc
Copy link
Copy Markdown
Contributor

Zoxc commented Apr 27, 2026

I'd just copy over the whole new file to keep the updated safety comments and microoptimizations, then just change it to share just the Registry type, so it doesn't make use of WorkerThread at all. The use of WorkerThread adds a null check and the indirection, so that would be slightly slower. That overhead can be avoided with #155688, but I'm a bit unsure about that change.

@zetanumbers
Copy link
Copy Markdown
Contributor Author

zetanumbers commented Apr 27, 2026

If I did that I would copy old code back due to this registry struct. I've copied all of the safety comments and microoptimizations. The aforementioned null check is unavoidable as it is done for REGISTRY thread-local too due to OnceCell::get returning an Option.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 27, 2026

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.

@nikomatsakis
Copy link
Copy Markdown
Contributor

@Zoxc (do you want to take this review, or should I?)

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

Labels

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.

4 participants