Skip to content

Inline WorkerThread pointer into a thread local#155688

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

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

Conversation

@zetanumbers
Copy link
Copy Markdown
Contributor

@zetanumbers zetanumbers commented Apr 23, 2026

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
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 23, 2026

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
Copy link
Copy Markdown
Contributor Author

zetanumbers commented Apr 23, 2026

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
Copy link
Copy Markdown
Contributor

Zoxc commented Apr 24, 2026

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.

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.

5 participants