Skip to content

Wide threads: the processor count is worked out once, not at every spread of work - #3570

Closed
tphira612 wants to merge 1 commit into
trustno1-coder:mainfrom
tphira612:perf/wide-threads-once
Closed

tphira612 wants to merge 1 commit into
trustno1-coder:mainfrom
tphira612:perf/wide-threads-once

Conversation

@tphira612

@tphira612 tphira612 commented Nov 30, 2026 •

Copy link
Copy Markdown

What it changes

wide_threads() in shadow.rs cached only VICTORY_WIDE_THREADS. Without it (the default), every call asked std::thread::available_parallelism() again. queued, wide_each and wide_each_scoped call it one to three times per spread of work, on the submitting thread. On Windows that call asks the system for the process's affinity and job limits each time.

The count is now worked out once in the OnceLock. The value, the clamps and the switch are unchanged. The helper threads are started once with this count anyway.

How it was tested

@github-actions github-actions Bot added the pr-performance Pull request: makes it faster or use less memory label Nov 30, 2026
@github-actions github-actions Bot changed the title [pr-performance] Wide threads: the processor count is worked out once, not at every spread of work Wide threads: the processor count is worked out once, not at every spread of work Nov 30, 2026
wide_threads() cached only VICTORY_WIDE_THREADS; without it, every call
asked std::thread::available_parallelism() again, and queued, wide_each
and wide_each_scoped call it one to three times per spread of work on the
submitting thread. On Windows that call asks the system for the process's
affinity and job limits: 862 to 998 ns a call on a Ryzen 9 5900X, 2 ns
cached (200,000 calls a sample, release build). The helper threads are
started once with this count, so a count that changed later would not
match them anyway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request: makes it faster or use less memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant