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

Closed
github-bot wants to merge 1 commit from github-bot/gh-3570 into main AGit
Owner

@⁠tphira612 on GitHub · 2026-11-30 01:13 UTC · original
tphira612:perf/wide-threads-once → main · +16 −7 · 1 files · 1 commits · closed without merging

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

  • Microbenchmark, Ryzen 9 5900X, release build, 200,000 calls per sample, three runs: 862–998 ns per call before, about 2 ns after. Both return 8. Frame times in the title not measured.
  • cargo test --locked -p victory-gpu --lib: shadow::wide_tests pass. Two failures are not from this change: every_switch_of_the_translator_is_in_the_key also fails on main, and a_change_is_saved_at_once_however_the_game_was_started passes when run alone.
  • cargo build --release --locked -p victory and cargo xtask policy --staged pass. Clippy is clean in victory-gpu; it stops on victory-shader errors already on main (fixed by #3560, #3530, #3385).
**@⁠tphira612** on GitHub · 2026-11-30 01:13 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3570) `tphira612:perf/wide-threads-once` → `main` · +16 −7 · 1 files · 1 commits · closed without merging ## 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 - Microbenchmark, Ryzen 9 5900X, release build, 200,000 calls per sample, three runs: **862–998 ns per call before, about 2 ns after**. Both return 8. Frame times in the title not measured. - `cargo test --locked -p victory-gpu --lib`: `shadow::wide_tests` pass. Two failures are not from this change: `every_switch_of_the_translator_is_in_the_key` also fails on `main`, and `a_change_is_saved_at_once_however_the_game_was_started` passes when run alone. - `cargo build --release --locked -p victory` and `cargo xtask policy --staged` pass. Clippy is clean in `victory-gpu`; it stops on `victory-shader` errors already on `main` (fixed by #3560, #3530, #3385).
wide_threads() cached only VICTORY_WIDE_THREADS; without it, every call
asked std:🧵: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.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 01:14:29 +00:00
github-bot force-pushed github-bot/gh-3570 from 7d04a35d14 to 4667446df6 2026-11-30 01:20:10 +00:00 Compare
github-bot closed this pull request 2026-11-30 01:20:11 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!3570
No description provided.