perf(gpu): cut thin hoist/heap_order stalls, skip no-op uploads, and coalesce ranges #13

Manually merged
github merged 1 commit from github-bot/gh-13 into mega-upgrade-v3 2026-12-04 20:20:04 +00:00 AGit
Owner

@⁠MahanYTT on GitHub · 2026-12-04 18:42 UTC · original
MahanYTT:perf/thin-hoist-heap-order → mega-upgrade-v3 · +302 −56 · 2 files · 1 commits · merged 2026-12-04 20:18 UTC

Summary

Addresses the submit-thread stalls, no-op texture upload claims, and redundant work observed in victory-ma-play-20261204-165800-18832.log:

  • Thin heap order: 184.6 ms total wait across 101 waits (longest 11.7 ms), 545,381 ranges cloned twice per pass.
  • Thin upload order: 60.2 ms total wait across 27 waits (longest 32.9 ms), 692/1,479 queued uploads had nothing to upload, 66 uploaded again.

Changes

crates/victory-gpu/src/texture/hoist.rs

  • Bound submit-thread wait: Lower default VICTORY_THIN_UPLOAD_WAIT_US from 50_000 µs (50 ms) to 500 µs (0.5 ms), preventing 32.9 ms single-frame stalls while still catching fast passes (env override preserved).
  • 8-slot epoch ring (EPOCH_SLOTS = 8): Replaces the 2-slot toggle so a single timed-out slow pass no longer re-stalls every alternating submission while finishing.
  • Lock-free idle fast path & accurate wait accounting: Hoist::take() returns immediately when total_open == 0 && queued == 0 without locking or calling Instant::now(), skips queue lock when empty, handles Duration::ZERO without condvar/timer overhead, and measures only actual condvar wait time.
  • Skip no-op uploads & deduplicate by staging buffer: needs_hoist skips already-uploaded clean textures (uploaded && !dirty), already-hoisted uploads, and host-written textures at both push() and take() (their own list still refreshes them in prelude_uploads). Hoist::push_unique deduplicates queued uploads per Arc<Staging> pointer within each batch.

crates/victory-gpu/src/host/heap_order.rs

  • Dedicated tight wait cap: Adds VICTORY_THIN_HEAP_WAIT_US (falling back to VICTORY_THIN_UPLOAD_WAIT_US, defaulting to 250 µs) so async victory-aside buffer sweeps (2–12 ms) no longer block the submit thread for 11.7 ms.
  • Zero-clone range moves & multi-pass coalescing: push() filters empty ranges up front; steps() consumes Vec<Pass> by value (eliminating 545k+ redundant Arc<Shadow> clones) and coalesces overlapping/adjacent (from, to) ranges per shadow when multiple passes accumulate.
  • O(1) prepend: Replaces copies.splice(0..0, steps) with direct assignment when copies is empty or steps.append(copies) otherwise.

Verification

  • cargo clippy --target x86_64-pc-windows-gnu -p victory-gpu -- -D warnings: 0 warnings, 0 errors.
  • cargo clippy --target x86_64-pc-windows-gnu -p victory-gpu --tests -- -D warnings: 0 warnings, 0 errors.
  • Standalone native rustc --edition 2024 --test execution of all 12 unit tests covering Hoist<T>, push_unique, needs_hoist_state, zero_limit_times_out_immediately, epochs_alternate, and coalesce_ranges: 12/12 passed.
**@⁠MahanYTT** on GitHub · 2026-12-04 18:42 UTC · [original](https://github.com/MahanYTT/VIctory-MA/pull/13) `MahanYTT:perf/thin-hoist-heap-order` → `mega-upgrade-v3` · +302 −56 · 2 files · 1 commits · merged 2026-12-04 20:18 UTC ## Summary Addresses the submit-thread stalls, no-op texture upload claims, and redundant work observed in `victory-ma-play-20261204-165800-18832.log`: - **Thin heap order**: 184.6 ms total wait across 101 waits (longest 11.7 ms), 545,381 ranges cloned twice per pass. - **Thin upload order**: 60.2 ms total wait across 27 waits (longest 32.9 ms), 692/1,479 queued uploads had nothing to upload, 66 uploaded again. ## Changes ### `crates/victory-gpu/src/texture/hoist.rs` - **Bound submit-thread wait**: Lower default `VICTORY_THIN_UPLOAD_WAIT_US` from `50_000` µs (50 ms) to `500` µs (0.5 ms), preventing 32.9 ms single-frame stalls while still catching fast passes (env override preserved). - **8-slot epoch ring (`EPOCH_SLOTS = 8`)**: Replaces the 2-slot toggle so a single timed-out slow pass no longer re-stalls every alternating submission while finishing. - **Lock-free idle fast path & accurate wait accounting**: `Hoist::take()` returns immediately when `total_open == 0 && queued == 0` without locking or calling `Instant::now()`, skips `queue` lock when empty, handles `Duration::ZERO` without condvar/timer overhead, and measures only actual condvar wait time. - **Skip no-op uploads & deduplicate by staging buffer**: `needs_hoist` skips already-uploaded clean textures (`uploaded && !dirty`), already-hoisted uploads, and host-written textures at both `push()` and `take()` (their own list still refreshes them in `prelude_uploads`). `Hoist::push_unique` deduplicates queued uploads per `Arc<Staging>` pointer within each batch. ### `crates/victory-gpu/src/host/heap_order.rs` - **Dedicated tight wait cap**: Adds `VICTORY_THIN_HEAP_WAIT_US` (falling back to `VICTORY_THIN_UPLOAD_WAIT_US`, defaulting to `250` µs) so async `victory-aside` buffer sweeps (2–12 ms) no longer block the submit thread for 11.7 ms. - **Zero-clone range moves & multi-pass coalescing**: `push()` filters empty ranges up front; `steps()` consumes `Vec<Pass>` by value (eliminating 545k+ redundant `Arc<Shadow>` clones) and coalesces overlapping/adjacent `(from, to)` ranges per shadow when multiple passes accumulate. - **O(1) prepend**: Replaces `copies.splice(0..0, steps)` with direct assignment when `copies` is empty or `steps.append(copies)` otherwise. ## Verification - `cargo clippy --target x86_64-pc-windows-gnu -p victory-gpu -- -D warnings`: 0 warnings, 0 errors. - `cargo clippy --target x86_64-pc-windows-gnu -p victory-gpu --tests -- -D warnings`: 0 warnings, 0 errors. - Standalone native `rustc --edition 2024 --test` execution of all 12 unit tests covering `Hoist<T>`, `push_unique`, `needs_hoist_state`, `zero_limit_times_out_immediately`, `epochs_alternate`, and `coalesce_ranges`: 12/12 passed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 18:43:36 +00:00
github manually merged commit 4ba58378c8 into mega-upgrade-v3 2026-12-04 20:20:04 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.