in_parallel runs on kept threads instead of starting new ones on every call (#163) #253
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!253
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-253"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ySKELLETONX on GitHub · 2026-11-26 13:01 UTC · original
ySKELLETONX:perf/parallel-pool→main· +248 −8 · 3 files · 1 commits · openin_parallelstarted up to five threads withstd::thread::scopeon every call, and the submitting thread calls it several times a submission (snapshots, read-backs, bounce copies). The profile in #163 put 1.2% of that thread inZwCreateThreadEx.Five threads are now kept (
victory-parallel-0..4, started on first use, incrates/victory-gpu/src/parallel.rs);in_parallelkeeps its pieces and its split, only where they run changes.How a call works
thread::scopedid; the thread goes on.Tests (
parallel::tests, no game data): every item done once; at most five helper threads over 50 calls; a call nested in a call; 8 threads calling at once; a panic in a kept thread reaches the caller and the pool still works; zero helpers runs on the caller. 20/20 runs green.cargo test -p victory-gpu --lib --locked: 119 passed, 0 failedcargo clippy -p victory-gpu --lib --tests: nothing in the changed filescargo xtask policy --staged: okMeasured (release, Ryzen 7 5700X3D, RX 7600 XT, Windows 11), start and join per call:
std::thread::scopeabout 280 µs, the kept threads under 1 µs. At several calls a submission that is roughly the 1.2% from #163; I have not measured it in the world.@adrianmjim on GitHub · 2026-11-26 21:44 UTC · original
Native Windows results for
21ee210on its base4f62c2a. Machine: Windows 11 (build 26300), 16 logical CPUs, Radeon RX 7900 XT (driver 32.0.32029.2010), Rust 1.98.1, MSVC target. #178 does the same job with five kept threads. To compare the two in the same session, I merged #178 (6325dc1) onto4f62c2alocally; the merge is clean. Other jobs held the CPU at 96-100% during all runs. The base cost per call is about twice what I measured in my #178 comment (about 170 µs then).Tests:
victory-gpu --libdebug runs, interleaved: 4 runs each of base, this PR and #178. The six newparallel::tests passed every time. The only failures were the knownwatch::guard-page flakes: 1 run on base and 1 on this PR.parallel::tests: 50 debug runs and 50 release runs, all passed.--lib --tests): no new warnings.Cost per call. I used the same local test as in my #178 comment: 3000 calls, a sum over the items, release build, medians of 5 alternating runs, in µs per call.
4f62c2a4f62c2a, after creating the host deviceI also counted the items done on threads other than the caller (medians of the same runs):
Then I gave each item more work (64 rounds of a multiply and shift mix). Each call had 256 to 16,384 items. No device, medians of 5 runs, µs per call, with the share of items done off the caller:
Nesting and several callers:
Design differences I noticed:
mpsc::Receiverbehind aMutex, and the lock is held duringrecv. So only one thread waits inrecvand the others wait for the lock. #178 uses aVecDequewithCondvar::notify_all. I did not check whether this causes the lower share above.VICTORY_HELPERS=0to start threads per call as before. This PR has none.Not tested: frame times in the title.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.