in_parallel shares its work with kept threads instead of making threads at every call #178
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!178
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-178"
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?
@SPFCChris on GitHub · 2026-11-25 19:32 UTC · original
SPFCChris:perf/kept-helper-threads→main· +189 −4 · 1 files · 2 commits · open## Problem
host::in_parallelmakes up to five threads withstd::thread::scopeat every call, and a submission calls it some tens of times:Shadow::copy_back, the snapshots inrun_deferred, the bounces and reads ofprepare_bindless. With 35 to 40 submissions a world frame that is hundreds of threads made and joined a frame, each announced to every loaded library.Sampled with
VICTORY_PROFILEin the world on a Radeon 8060S (20 s, 9,415 samples of the submitting thread): 9.4 % of its samples were inZwCreateThreadEx, all underin_parallel(copy_back:557,execute_inner:1308and:1315ata59f3e5).Change
Five threads are kept (
victory-helper) and offered each call's work. The caller does its own share as before; when that returns nothing is left to take, so it closes the job and waits only for threads that are already inside it. A thread that comes late finds the job closed and never touches the caller's closure. That is also why a call from inside a piece cannot stand: nobody waits for a thread that has not started.VICTORY_HELPERS=0makes threads at each call as before, for comparison.One file,
crates/victory-gpu/src/host.rs; no new dependency.Measured
Radeon 8060S (Ryzen AI Max+ 395), diag build, Series X profile, the opening cutscene, 220 s in the world per run, every frame's time logged. Same binary,
VICTORY_HELPERS=0against the default, runs alternated. Median frame time of the frames in a band of draws per frame, so that the runs are compared like for like:Two further runs with kept threads, taken for another comparison, gave 200 / 238 and 216 / 244 ms in the two bands. In a profile taken afterwards
ZwCreateThreadExis gone from the submitting thread's samples.Run 2 of "threads made per call" ended early: the title's own crash handler came up after 113 s in the world (445 frames; a first-chance access violation in
ntdll, cause not looked into), so its figures cover a shorter window.These runs were on
a59f3e5plus #148, which this GPU needs to draw the world at all. This branch is on000ffdd; the change is the same lines.Tested
cargo test -p victory-gpu --lib --locked: 116 passed, 0 failed, 4 ignored. Three of them are new: every piece done once over 500 calls on the same threads, a call from inside a piece returns, a panic in a piece reaches the caller and the threads go on.cargo clippy -p victory-gpu --all-targets --locked: no warning in the new code.Not tested
diagnostics.AI-assisted (Claude Code); no game data.
🤖 Generated with Claude Code
@KernelSmoker on GitHub · 2026-11-25 19:38 UTC · original
Independent verification on PR head
6f563b1(Bazzite Linux 45 x86_64, Rust 1.98.1, Intel Core i9-11900K, GE-Proton 10-34 / Wine 10.0):diagnosticsbuild (noted as untested in the PR):cargo check --workspace --all-targets --locked --offline --target x86_64-pc-windows-gnupassed cleanly (0 warnings inhost.rs).--all-features):cargo clippy -p victory-gpu --all-targets --all-features --locked --offline --target x86_64-pc-windows-gnupassed with 0 new warnings inhost::helpers.host::helpers::tests(default kept threads): 3 passed, 0 failed across 10/10 consecutive runs (~0.01s per run).VICTORY_HELPERS=0(host::helpers::tests, thread-per-call): 3 passed, 0 failed (0.54s for the same 3 tests).Code review notes on
mod helpers:SeqCstDekker handoff betweenrunning.fetch_add(1)/closed.load()(workers) andclosed.store(true)/running.load()(callerClose::drop), plus theArc<Job>lifetime keepingidlealive untilnotify_all()finishes andCloserunning on unwind, all look sound.JOBSis a FIFOVecDequeandClose::dropdoes not prune closed entries. When calls finish quickly or nest while all 5 helpers are busy (e.g.a_call_from_inside_a_piece_returns), already-closedArc<Job>entries pile up at the front ofJOBSand helpers have to pop/check/notify them before reaching a live job pushed at the back. Callingjobs.retain(|j| !j.closed.load(Ordering::Relaxed));underJOBS.lock()right beforejobs.extend(...)inhelpers::run(or pruning inClose::drop) would keepJOBSbounded and avoid waking helpers into stale entries.(No live title benchmark run performed here; this covers the non-
diagnosticsbuild, clippy, concurrency review, and Wine unit tests on Intel i9-11900K.)@MamaLeVrai on GitHub · 2026-11-26 05:11 UTC · original
Concurrency check on Windows/RDNA2 (RX 6950 XT, Windows 11 build 26300, Rust 1.98.1). I merged this PR (
6325dc1) ontomain4f62c2aplus #210, which fixeslist::tests::lists_are_cut_at_waits_that_follow_work, a test that fails in every release run onmain. Then I ran the releasevictory-gpulib test binary 10 times, with the default thread count:watch::tests::written_pages_are_reported_to_every_asker(#102), and 1 run died without a result line.No new failure, deadlock or hang showed up in these runs. Ten runs are a small sample for races. Not run in the game.
harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300
AI-assisted (Claude Code); no game data.
@adrianmjim on GitHub · 2026-11-26 19:40 UTC · original
Native Windows results for
6325dc1, which includes the queue pruning from the review. Base000ffdd. Machine: Windows 11 (build 26300), 16 logical CPUs, Radeon RX 7900 XT (driver 32.0.32029.2010), Rust 1.98.1, MSVC target. Other jobs were running on the machine at the same time.Unit tests (
victory-gpu --lib, debug build), alternating between variants:000ffdd: 106 runs each. PR merged onto current main4f62c2a: 105 runs (the merge is clean). Plain4f62c2a: 55 runs. PR head withVICTORY_HELPERS=0: 55 runs.host::helperstests passed in every run.000ffdd4f62c2a4f62c2aVICTORY_HELPERS=0watch::guard-page testsframe::tests::waits_end_on_ticks_and_count_framespipeline::library::tests::concurrent_atomic_writes_publish_one_complete_filequeue::(present_runs_after_a_queues_wait, oncequeue_signals_complete_at_once)query::(read back the 0xEEEE... stand-in value)query::failures and the abort are not specific to this PR. I ran only thequery::tests 60 times on each side. On000ffdd, 2 of 60 runs failed (one of them aborted). On the PR head, 1 of 60 aborted. The abort is instd::process::abort. I did not find its caller.Cost per call, native (release build). I used a local test that is not part of the PR. It times 3000
in_parallelcalls after 200 warm-up calls, with a sum over 48 items (least 8), 1024 items (least 8) and 65,536 items (least 16). Figures are medians of 5 alternating runs, in µs per call:000ffddVICTORY_HELPERS=0000ffdd, after creating the host D3D12 deviceVICTORY_HELPERS=0, after creating the deviceVICTORY_HELPERS=0gives about the same numbers as000ffdd.Not tested:
in_parallelat the same time.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.