perf(gpu): speed up copy_runs, pieces::take, write-watch journal, and preparing hot paths #306
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/gamingwithhomie--larp!306
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-306"
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?
@talfour on GitHub · 2026-12-05 22:54 UTC · original
talfour:perf/copy-runs-and-preparing→main· +566 −149 · 5 files · 1 commits · merged 2026-12-05 23:10 UTCSummary
Follow-up CPU overhead optimizations on top of #185 targeting
Host::submit/preparinghot paths inlarp-gpu(no new dependencies, no shader-cache invalidation, zero extra RAM):Sort-and-cluster fast path for
copy_runs+ generation-taggedrun_map+ zero-allocSpans::add(crates/larp-gpu/src/host.rs)copy_runs()taking 3.0–4.1 ms/frame at 7k–11k draws/frame (~50% of allpreparingtime — more than 2× slower than the actual D3D12CopyBufferRegion+ExecuteCommandListswork at ~1.5 ms/frame) due to rebuilding and destroying twoBTreeMap-backedHashMaps and allocatingVec<u64>insideSpans::addfor thousands of mostly disjoint copies.(to_ptr, at, end, idx)into a reused thread-local buffer, sorts once by(to_ptr, at), and partitions into connected overlap components:Spansandrun_mapcompletely in both passes.Spanswithout hash lookups, and pass 2 tracks only surviving clustered copies using au32generation tag instead of clearing/freeingBTreeMaps on every run split.placesVecincopy_send_refs.host::copy_runs_tests::copy_runs_matches_reference_fuzz) verifying bit-for-bit identical output against the reference implementation.Lock-free fast path in
pieces::take()+ off-lock/reaper drops inpieces::State::settle()(crates/larp-gpu/src/pieces.rs,host.rs)copiesnon-empty (HAS_COPIES) and earliestrestingsubmission (NEXT_REST) in atomics sopieces::take()skips thepieces::STATEmutex (contended with streamingnew_bufferD3D12 allocations) when idle.Buffer/Spandrops out of theSTATElock and offloads them viahost::reap_nowtolarp-reaperwhenLARP_OPT_RELEASE_HELDis active.by_systemandby_objecttoFastMap.Write-watch journal contention & redundant
ask_aheadelimination (crates/larp-gpu/src/watch.rs,host.rs)watch::JOURNALfromMutextoRwLockso parallellarp-widerefresh threads take shared read locks on theask_oncefast path.Journal::keptin an atomicKEPTsoBatch::flush/ask_ahead/ask_ahead_doneskip allocatingranges/pieces, lockingGUARDS, and sorting whenask_oncealready covers the submission.PAGEbeforeBTreeMap::insert, and removes the temporaryVecinwatch::writes.FastMap/FastSetand thread-local buffer reuse inpreparing(host.rs,shadow.rs,texevents.rs)HashMap/HashSetwithFastMap/FastSeton integer/pointer keys inPLANNED,gpu_writes,ASK_SCRATCH,Batch::index,shadow::Pending/Flights, andtexevents::Objects.PLANNED,ASK_SCRATCH, andBatchallocations (bounded byKEEP_BYTES), removes per-Plannedvec!allocations inask_once, and short-circuitsPlanned::Waitscanning per list when none exist.Measured In-Game Results (RX 9070 XT, 1440p, Series X profile, on top of #185)
prep3.3–3.6 ms,copy_runs0.57–1.07 msprep2.8 ms,copy_runs0.05–0.06 mscopy_runsprep6.4 ms,copy_runs3.25 msprep3.9–4.0 ms,copy_runs0.11–0.45 msprepprep8.7–9.3 msprep3.8–4.2 ms,copy_runs0.45–0.54 msprepprep7.9–9.3 ms,copy_runs4.05–4.07 msprep4.2–4.6 ms,copy_runs0.42–0.50 mscopy_runs, -3.6 mspreppieces::take()measured 0.00–0.03 ms/f andwatch::ask_once0.01–0.03 ms/f.Verification
cargo test --lib --locked -p larp-gpu— 19 passed, 0 failed (including 2,000-case fuzz testhost::copy_runs_tests::copy_runs_matches_reference_fuzz)cargo check --release --locked -p larp— passed with zero new warningscargo check --release --locked -p larp-gpu --features diagnostics— passed with zero new warningscrates/larp-shaderorshader_cache.rs(existing shader/pipeline caches stay valid)