Skip to content

reduce default executor spins from 4 to 0#262

Merged
tzcnt merged 2 commits into
mainfrom
reduce_executor_spins
Jun 25, 2026
Merged

reduce default executor spins from 4 to 0#262
tzcnt merged 2 commits into
mainfrom
reduce_executor_spins

Conversation

@tzcnt

@tzcnt tzcnt commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Previously the work stealing loop would only pause between each full round of work stealing attempts. Now, there is a pause inside of the work stealing loop to reduce cross-cache traffic. As a result, the overall work stealing operation takes a bit longer to complete. That change went out in v1.6. BTW, I profiled it across all workloads and didn't observe any negative effects - it seemed to only help.

I have, however, noticed that extra spinning doesn't seem to be helpful under this new regime. It pollutes lightly-loaded / latency-bound profiles with a lot of ex_cpu::make_worker time that isn't doing anything. For cases where you want to actively spin to minimize latency, you'll want to set_spins() to a much higher than the old default of 4 - probably to something like 100+. So I'm changing the default spins to 0.

There's still 1 guaranteed spin baked into the design - after failing to find work and marking the thread as going to sleep, we have to double check all the queues. Then, there is a std::atomic::wait() on the sleep_wait variable, which does some spinning internally.

@tzcnt tzcnt merged commit 1a4b8e2 into main Jun 25, 2026
0 of 53 checks passed
@tzcnt tzcnt deleted the reduce_executor_spins branch June 25, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant