Skip to content

Inline WorkerThread pointer into a thread local#155688

Open
zetanumbers wants to merge 1 commit into
rust-lang:mainfrom
zetanumbers:worker_thread_state
Open

Inline WorkerThread pointer into a thread local#155688
zetanumbers wants to merge 1 commit into
rust-lang:mainfrom
zetanumbers:worker_thread_state

Conversation

@zetanumbers

@zetanumbers zetanumbers commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

I've got this idea while implementing #155649. It's not as clean as I've expected but it did get rid of many unsafe blocks. I can also remove these unsafe blocks without changing WORKER_THREAD_STATE's type by utilizing new safe WorkerThread functions.

@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 23, 2026
@rustbot

rustbot commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

r? @chenyukang

rustbot has assigned @chenyukang.
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 73 candidates
  • Random selection from 19 candidates

@zetanumbers

Copy link
Copy Markdown
Contributor Author

r? @nnethercote

@rustbot rustbot assigned nnethercote and unassigned chenyukang Apr 23, 2026
@zetanumbers

zetanumbers commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

Doesn't seem to influence the performance overall, but noise level is a bit too big on my machine. Perhaps @Zoxc has better environment.

Benchmarkbase~main~6new~worker_thread_state~2
TimeTime%
🟣 hyper:check0.1121s0.1105s💚 -1.45%
🟣 hyper:check:initial0.1219s0.1279s💔 4.92%
🟣 hyper:check:unchanged0.0744s0.0771s💔 3.73%
🟣 clap:check0.3701s0.3723s 0.58%
🟣 clap:check:initial0.4354s0.4341s -0.31%
🟣 clap:check:unchanged0.2227s0.2237s 0.45%
🟣 syn:check0.4147s0.4190s💔 1.04%
🟣 syn:check:initial0.5133s0.5073s💚 -1.15%
🟣 syn:check:unchanged0.3295s0.3299s 0.09%
🟣 regex:check0.2623s0.2557s💚 -2.53%
🟣 regex:check:initial0.3098s0.3063s💚 -1.13%
🟣 regex:check:unchanged0.1821s0.1836s 0.79%
Total3.3483s3.3473s -0.03%
Summary1.0000s1.0042s 0.42%

@zetanumbers

Copy link
Copy Markdown
Contributor Author

Also I haven't yet updated comments. TODO

@Zoxc

Zoxc commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

I was thinking a scoped thread local would make sense for this too. cc @cuviper in case that makes sense for upstream Rayon.

My guess is that the indirection doesn't have much performance overhead. A Rayon benchmark would be more suitable, but not sure it would pick that up.

@nnethercote

Copy link
Copy Markdown
Contributor

I am uncertain about the status of this PR.

@zetanumbers: has the TODO on the comments been addressed?

I was thinking a scoped thread local would make sense for this too

Is that a suggestion for a change to this PR, or a follow-up, or something else?

@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 May 1, 2026
@rustbot

rustbot commented May 1, 2026

Copy link
Copy Markdown
Collaborator

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

@Zoxc

Zoxc commented May 1, 2026

Copy link
Copy Markdown
Contributor

Is that a suggestion for a change to this PR

An alternative which I think would be cleaner if this isn't a performance improvement.

@rust-bors

rust-bors Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #159498) 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.

5 participants