perf(victory-gpu): reduce fence waiter lock contention and queue submission allocations #411

Closed
github-bot wants to merge 2 commits from github-bot/gh-411 into main AGit
Owner

@⁠Lewandox on GitHub · 2026-11-26 17:53 UTC · original
Lewandox:perf/victory-gpu-fence-and-queue → main · +182 −77 · 2 files · 2 commits · closed without merging

Summary

Reduces mutex contention on GPU fence signaling/waiting and removes avoidable hot-path allocations and O(N) queue shifts during command-list submission.

Changes

  1. fence.rs — lock-free fast path & out-of-lock SetEvent:

    • In set_event_on_completion, check fence.value.load(Ordering::Acquire) >= value before calling merge_fence_asked or locking fence.waiters, firing the event immediately when already completed.
    • In set, extract due waiters under fence.waiters and drop the mutex guard before calling SetEvent so concurrent callers are not blocked behind Win32 kernel calls.
    • Added concurrent_waiters_and_signals_never_miss_an_event unit test.
  2. queue.rs — O(1) held-queue draining & allocation reduction:

    • Switched Queue::held from Vec<Held> to VecDeque<Held> so release_held pops from the front in O(1) instead of shifting elements via Vec::remove(0).
    • Added execute_host_lists to pass a single-element stack slice (&[h]) on single-list submissions and pre-sized Vec::with_capacity for multi-list submissions, avoiding per-submission heap allocations in submit_cut, submit_split, execute, and release_held.
    • Pre-sized pieces in submit_cut and submit_split, removed the intermediate by[from..to].concat() temporary Vec, and reused the queues scratch buffer across release_held loop iterations.
    • Centralized WAITING registration in mark_waiting.
    • Added held_signals_release_in_fifo_order_after_wait unit test.

Verification

  • cargo test -p victory-gpu --lib fence::tests (default and --features diagnostics)
  • cargo test -p victory-gpu --lib queue::tests (default and --features diagnostics)
  • cargo xtask policy
**@⁠Lewandox** on GitHub · 2026-11-26 17:53 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/411) `Lewandox:perf/victory-gpu-fence-and-queue` → `main` · +182 −77 · 2 files · 2 commits · closed without merging ## Summary Reduces mutex contention on GPU fence signaling/waiting and removes avoidable hot-path allocations and O(N) queue shifts during command-list submission. ### Changes 1. **`fence.rs` — lock-free fast path & out-of-lock `SetEvent`**: - In `set_event_on_completion`, check `fence.value.load(Ordering::Acquire) >= value` before calling `merge_fence_asked` or locking `fence.waiters`, firing the event immediately when already completed. - In `set`, extract due waiters under `fence.waiters` and drop the mutex guard before calling `SetEvent` so concurrent callers are not blocked behind Win32 kernel calls. - Added `concurrent_waiters_and_signals_never_miss_an_event` unit test. 2. **`queue.rs` — O(1) held-queue draining & allocation reduction**: - Switched `Queue::held` from `Vec<Held>` to `VecDeque<Held>` so `release_held` pops from the front in O(1) instead of shifting elements via `Vec::remove(0)`. - Added `execute_host_lists` to pass a single-element stack slice (`&[h]`) on single-list submissions and pre-sized `Vec::with_capacity` for multi-list submissions, avoiding per-submission heap allocations in `submit_cut`, `submit_split`, `execute`, and `release_held`. - Pre-sized `pieces` in `submit_cut` and `submit_split`, removed the intermediate `by[from..to].concat()` temporary `Vec`, and reused the `queues` scratch buffer across `release_held` loop iterations. - Centralized `WAITING` registration in `mark_waiting`. - Added `held_signals_release_in_fifo_order_after_wait` unit test. ## Verification - `cargo test -p victory-gpu --lib fence::tests` (default and `--features diagnostics`) - `cargo test -p victory-gpu --lib queue::tests` (default and `--features diagnostics`) - `cargo xtask policy`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:57:54 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 18:27 UTC · original

Thanks. The fence part is the same as #415, which is being merged first, so this will conflict on fence.rs: could you rebase and keep only the queue.rs part?

One fix there: execute_host_lists skips host.execute when the single list has no host_list. Before, host.execute(&[]) still ran and called merge_send(Sync) (host.rs, execute). Please keep calling host.execute(&[]) in that case.

🤖 Generated with Claude Code

**@⁠LooperSalty** on GitHub · 2026-11-26 18:27 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/411#issuecomment-7200487355) Thanks. The fence part is the same as #415, which is being merged first, so this will conflict on `fence.rs`: could you rebase and keep only the `queue.rs` part? One fix there: `execute_host_lists` skips `host.execute` when the single list has no `host_list`. Before, `host.execute(&[])` still ran and called `merge_send(Sync)` (`host.rs`, `execute`). Please keep calling `host.execute(&[])` in that case. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠Lewandox on GitHub · 2026-11-26 18:56 UTC · original

Thanks for the review!

  • Fixed execute_host_lists so a single-list submission with no host_list still calls host.execute(&[]), preserving merge_send(Sync).
  • Note: #415 (and #424) were closed as duplicates of this PR and were not merged, so keeping both fence.rs and queue.rs here has no conflict with main. (Happy to split fence.rs out if you still prefer them separate!)

Re-verified locally with cargo test -p victory-gpu --lib fence::tests and queue::tests (default and --features diagnostics) + cargo xtask policy.

**@⁠Lewandox** on GitHub · 2026-11-26 18:56 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/411#issuecomment-7201020139) Thanks for the review! - Fixed `execute_host_lists` so a single-list submission with no `host_list` still calls `host.execute(&[])`, preserving `merge_send(Sync)`. - Note: #415 (and #424) were closed as duplicates of this PR and were not merged, so keeping both `fence.rs` and `queue.rs` here has no conflict with `main`. (Happy to split `fence.rs` out if you still prefer them separate!) Re-verified locally with `cargo test -p victory-gpu --lib fence::tests` and `queue::tests` (default and `--features diagnostics`) + `cargo xtask policy`.
github-bot force-pushed github-bot/gh-411 from 8176019683 to 82efbf094b 2026-11-26 19:50:47 +00:00 Compare
github-bot force-pushed github-bot/gh-411 from 82efbf094b to dbac17de62 2026-11-27 00:36:06 +00:00 Compare
github-bot closed this pull request 2026-11-27 00:36:06 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 23:09 UTC · original

Closing after #454 moved third_party/victory to the Vice-Tay base (TaynanGT/Vice-Tay a252348).

The files do not apply to the new base any more, and the change came without a measurement (rule 2 of AGENTS.md asks for one for performance work).

Thanks for the work. If you measure a gain on the new base, a new PR against main is welcome.

🤖 Closed by Claude Code on behalf of the maintainer

**@⁠LooperSalty** on GitHub · 2026-11-26 23:09 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/411#issuecomment-7205297535) Closing after #454 moved `third_party/victory` to the Vice-Tay base (TaynanGT/Vice-Tay a252348). The files do not apply to the new base any more, and the change came without a measurement (rule 2 of AGENTS.md asks for one for performance work). Thanks for the work. If you measure a gain on the new base, a new PR against `main` is welcome. _🤖 Closed by [Claude Code](https://claude.com/claude-code) on behalf of the maintainer_

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.