Helper threads: KLBF_WIDE_THREADS and KLBF_WIDE_MIN for A/B runs (both off) #403

Open
Zensura6427 wants to merge 1 commit from upstream-pr/403 into v21
Zensura6427 commented 2026-12-01 03:57:19 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Zensura6427 on 2026-12-01T03:57:19Z.


As asked in #402: the helper-thread split as two switches, so it can be measured per CPU. Both are off by default: unset, nothing changes.

What it does

  • KLBF_WIDE_THREADS=1..16: the number of threads kept for wide() / wide_each(). Unset, it stays available_parallelism()/4 clamped to 2..6 (3 on a 12-thread Ryzen 5 5600X). Read once (OnceLock) and logged at start (threads kept for work spread over threads).
  • KLBF_WIDE_MIN=n: spreads of fewer than n pieces run on the calling thread, without waking the kept threads. Unset or invalid, it is 0, as before.
  • Diagnostics: a new line beside work the preparing thread spread over the kept threads splits that thread's time into its own jobs and waiting for the helpers' last jobs, and counts spreads run on the calling thread. It is also written when every spread ran there (first_lines_due).

Only crates/victory-gpu/src/shadow.rs changes. There are two unit tests (wide_threads_tests, wide_min_tests).

Measured (RX 9070 XT + Ryzen 5 5600X, BM-v1 5:00, the same save, all CERTIFIED; details in #402)

setting avg fps refreshes, ms/frame
default (3 helpers) 10.2 / 10.9 ~30
KLBF_WIDE_THREADS=5 10.4 / 10.7 ~27.5
KLBF_WIDE_THREADS=8 10.7 / 10.0 ~26
KLBF_WIDE_MIN=8 10.7 40.2
KLBF_WIDE_MIN=64 11.2 38.4

With the default, the preparing thread stood about 30 ms a frame in spreads: 26.2 ms of its own jobs and 5.9 ms waiting. On this machine the frame rate stays within run-to-run noise (about ±0.7 fps). It is offered as a tool for measuring other CPUs, not as a speed-up.

Checked

  • Rebased on v21 (v26.11.24, 92aa6f4); the patch applies cleanly.
  • cargo test -p victory-gpu --lib shadow::: 46 passed.
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean.
  • The benchmarks above were run on the same change on v26.11.19 (b7f96e4). The shader fingerprint is unchanged (737ade6b88ac8104).

Refs #402

🤖 Generated with Claude Code

<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5578685543 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/403). Originally posted by [Zensura6427](https://github.com/Zensura6427) on 2026-12-01T03:57:19Z. --- As asked in #402: the helper-thread split as two switches, so it can be measured per CPU. **Both are off by default: unset, nothing changes.** ## What it does - **`KLBF_WIDE_THREADS=1..16`**: the number of threads kept for `wide()` / `wide_each()`. Unset, it stays `available_parallelism()/4` clamped to 2..6 (3 on a 12-thread Ryzen 5 5600X). Read once (`OnceLock`) and logged at start (`threads kept for work spread over threads`). - **`KLBF_WIDE_MIN=n`**: spreads of fewer than `n` pieces run on the calling thread, without waking the kept threads. Unset or invalid, it is 0, as before. - **Diagnostics**: a new line beside `work the preparing thread spread over the kept threads` splits that thread's time into its **own jobs** and **waiting for the helpers' last jobs**, and counts spreads run on the calling thread. It is also written when every spread ran there (`first_lines_due`). Only `crates/victory-gpu/src/shadow.rs` changes. There are two unit tests (`wide_threads_tests`, `wide_min_tests`). ## Measured (RX 9070 XT + Ryzen 5 5600X, BM-v1 5:00, the same save, all CERTIFIED; details in #402) | setting | avg fps | refreshes, ms/frame | |---|---|---| | default (3 helpers) | 10.2 / 10.9 | ~30 | | `KLBF_WIDE_THREADS=5` | 10.4 / 10.7 | ~27.5 | | `KLBF_WIDE_THREADS=8` | 10.7 / 10.0 | ~26 | | `KLBF_WIDE_MIN=8` | 10.7 | 40.2 | | `KLBF_WIDE_MIN=64` | 11.2 | 38.4 | With the default, the preparing thread stood about 30 ms a frame in spreads: **26.2 ms of its own jobs and 5.9 ms waiting**. On this machine the frame rate stays within run-to-run noise (about ±0.7 fps). It is offered as a tool for measuring other CPUs, not as a speed-up. ## Checked - Rebased on `v21` (v26.11.24, `92aa6f4`); the patch applies cleanly. - `cargo test -p victory-gpu --lib shadow::`: 46 passed. - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings`: clean. - The benchmarks above were run on the same change on v26.11.19 (`b7f96e4`). The shader fingerprint is unchanged (`737ade6b88ac8104`). Refs #402 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PastiiJay commented 2026-12-01 03:59:44 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-12-01T03:59:44Z.


thanks a lot @Zensura6427, that was quick! the team will review it and run it through the checks.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7300269891 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/403#issuecomment-7300269891). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-12-01T03:59:44Z. --- thanks a lot @Zensura6427, that was quick! the team will review it and run it through the checks.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/403:upstream-pr/403'
git switch 'upstream-pr/403'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'v21'
git merge --no-ff 'upstream-pr/403'
git switch 'upstream-pr/403'
git rebase 'v21'
git switch 'v21'
git merge --ff-only 'upstream-pr/403'
git switch 'upstream-pr/403'
git rebase 'v21'
git switch 'v21'
git merge --no-ff 'upstream-pr/403'
git switch 'v21'
git merge --squash 'upstream-pr/403'
git switch 'v21'
git merge --ff-only 'upstream-pr/403'
git switch 'v21'
git merge 'upstream-pr/403'
git push origin 'v21'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
PastiiJay/klbf-lab!403
No description provided.