perf(queue): pipeline present drain, unbounded live batching, and lock-free wake #19

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

@⁠MahanYTT on GitHub · 2026-12-04 18:59 UTC · original
MahanYTT:perf/queue-async-submit → mega-upgrade-v3 · +541 −133 · 2 files · 1 commits · merged 2026-12-04 20:18 UTC

Summary

Optimizes VICTORY_ASYNC_SUBMIT queueing, batching, and present pipelining in crates/victory-gpu/src/queue/behind.rs and crates/victory-gpu/src/queue.rs to reduce the 27.1 ms/frame title-thread stall at presents and lock/dequeue overhead on victory-submit.

Root Causes & Fixes

  1. Present drain pipelining (queued_presents vs presents): Lane::wait_presents(most) previously blocked title threads until the earlier Job::Present::go() (show_planes / host.present_placed) completely finished. For most > 0 (default VICTORY_SUBMIT_FRAMES=1), queued_presents is now decremented and present_waiters notified as soon as the earlier present is dequeued to run (after all prior submissions/signals have executed), overlapping title CPU recording with host presentation while keeping wait_presents(0) synchronous.
  2. Unbounded live batching window in Lane::serve(): serve() previously snapshotted limit = state.next before look(limit), causing take_along (e.number < limit) to stop joining newly arrived ready submissions and chop VICTORY_JOIN_PARTS batches prematurely. serve() now uses u64::MAX when no drain() / wait_runs() waiter is active, and immediately bounds to state.next when need_served is set so drains never starve.
  3. Lock-free wake() fast path & waiter-gated condvar notifications: Moved asked (AtomicU64), has_items (AtomicBool), and parked (AtomicBool) outside the mutex with SeqCst Dekker pairing so wake() takes zero locks/syscalls when empty or while the worker is already awake, push/push_one/push_behind only notify work when the worker is parked, and moved.notify_all() only fires when a relevant waiter count is non-zero.
  4. Unfolding outside the line lock & direct unfold-to-execute: Lane::unfold_outside detaches/unfolds folded Job::Lists entries without holding Lane::state, executes immediately ready parts directly without re-inserting into VecDeque or restarting step(), and feeds remaining parts into take_along locally before touching state.items.
  5. Dequeue & present micro-optimizations: O(1) front fast path in step() when the oldest entry has no wait, reusable heads buffer, single-lock has_present and floor/raise tracking, Work::can_take_along() + pre-pop shows() skip, limit check before runs Vec allocation and in-place Job::Joined mutation in Job::take_along, zero-alloc Lane::push_one, and skipping redundant host_transition calls in queue.rs::present() when thin::wanted() is active.

Verification

  • cargo clippy --target x86_64-pc-windows-msvc -p victory-gpu -- -D warnings (default, --tests, --features diagnostics, --features ab): 0 warnings, 0 errors.
  • All 10 Lane unit tests in behind.rs (7 existing + 3 new tests covering present pipelining, lock-free unfolding/batching order preservation, and live serve() batching + drain()): 10 passed, 0 failed.
**@⁠MahanYTT** on GitHub · 2026-12-04 18:59 UTC · [original](https://github.com/MahanYTT/VIctory-MA/pull/19) `MahanYTT:perf/queue-async-submit` → `mega-upgrade-v3` · +541 −133 · 2 files · 1 commits · merged 2026-12-04 20:18 UTC ## Summary Optimizes `VICTORY_ASYNC_SUBMIT` queueing, batching, and present pipelining in `crates/victory-gpu/src/queue/behind.rs` and `crates/victory-gpu/src/queue.rs` to reduce the 27.1 ms/frame title-thread stall at presents and lock/dequeue overhead on `victory-submit`. ### Root Causes & Fixes 1. **Present drain pipelining (`queued_presents` vs `presents`)**: `Lane::wait_presents(most)` previously blocked title threads until the earlier `Job::Present::go()` (`show_planes` / `host.present_placed`) completely finished. For `most > 0` (default `VICTORY_SUBMIT_FRAMES=1`), `queued_presents` is now decremented and `present_waiters` notified as soon as the earlier present is dequeued to run (after all prior submissions/signals have executed), overlapping title CPU recording with host presentation while keeping `wait_presents(0)` synchronous. 2. **Unbounded live batching window in `Lane::serve()`**: `serve()` previously snapshotted `limit = state.next` before `look(limit)`, causing `take_along` (`e.number < limit`) to stop joining newly arrived ready submissions and chop `VICTORY_JOIN_PARTS` batches prematurely. `serve()` now uses `u64::MAX` when no `drain()` / `wait_runs()` waiter is active, and immediately bounds to `state.next` when `need_served` is set so drains never starve. 3. **Lock-free `wake()` fast path & waiter-gated condvar notifications**: Moved `asked` (`AtomicU64`), `has_items` (`AtomicBool`), and `parked` (`AtomicBool`) outside the mutex with SeqCst Dekker pairing so `wake()` takes zero locks/syscalls when empty or while the worker is already awake, `push`/`push_one`/`push_behind` only notify `work` when the worker is parked, and `moved.notify_all()` only fires when a relevant waiter count is non-zero. 4. **Unfolding outside the line lock & direct unfold-to-execute**: `Lane::unfold_outside` detaches/unfolds folded `Job::Lists` entries without holding `Lane::state`, executes immediately ready parts directly without re-inserting into `VecDeque` or restarting `step()`, and feeds remaining parts into `take_along` locally before touching `state.items`. 5. **Dequeue & present micro-optimizations**: O(1) front fast path in `step()` when the oldest entry has no wait, reusable `heads` buffer, single-lock `has_present` and `floor`/`raise` tracking, `Work::can_take_along()` + pre-pop `shows()` skip, limit check before `runs` Vec allocation and in-place `Job::Joined` mutation in `Job::take_along`, zero-alloc `Lane::push_one`, and skipping redundant `host_transition` calls in `queue.rs::present()` when `thin::wanted()` is active. ### Verification - `cargo clippy --target x86_64-pc-windows-msvc -p victory-gpu -- -D warnings` (default, `--tests`, `--features diagnostics`, `--features ab`): 0 warnings, 0 errors. - All 10 `Lane` unit tests in `behind.rs` (7 existing + 3 new tests covering present pipelining, lock-free unfolding/batching order preservation, and live `serve()` batching + `drain()`): 10 passed, 0 failed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 19:00:45 +00:00
github manually merged commit 4ba58378c8 into mega-upgrade-v3 2026-12-04 20:20:06 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.