perf(victory-gpu): lock-free fence fast path and signal events outside waiters mutex #415

Closed
github-bot wants to merge 1 commit from github-bot/gh-415 into main AGit
Owner

@⁠Lewandox on GitHub · 2026-11-26 17:58 UTC · original
Lewandox:perf/fence-lockfree-fastpath-and-unlock-signal → main · +72 −13 · 1 files · 1 commits · closed without merging

Summary

Reduces Fence::waiters mutex contention and avoids holding the lock across Win32 SetEvent calls (third_party/victory/crates/victory-gpu/src/fence.rs):

  1. Lock-free fast path in set_event_on_completion:
    • Checks fence.value.load(Ordering::Acquire) >= value before acquiring fence.waiters.lock(), avoiding mutex acquisition altogether for already-completed fence values (and drops the mutex before calling set_event when the re-check under the lock observes completion).
  2. Signal Win32 events outside fence.waiters mutex in set():
    • Atomically updates fence.value and extracts reached waiters under fence.waiters.lock() (with zero heap allocation when waiters is empty), releases the mutex, and calls SetEvent outside the lock so concurrent callers do not block on kernel event signaling.
  3. Concurrency regression test:
    • Adds concurrent_wait_and_signal_never_loses_a_wakeup racing 128 set_event_on_completion registrations against concurrent set signals to verify zero lost wakeups.

Verification

  • cargo test -p victory-gpu --lib fence::tests (default and --features diagnostics)
  • cargo xtask policy inside third_party/victory
**@⁠Lewandox** on GitHub · 2026-11-26 17:58 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/415) `Lewandox:perf/fence-lockfree-fastpath-and-unlock-signal` → `main` · +72 −13 · 1 files · 1 commits · closed without merging ## Summary Reduces `Fence::waiters` mutex contention and avoids holding the lock across Win32 `SetEvent` calls (`third_party/victory/crates/victory-gpu/src/fence.rs`): 1. **Lock-free fast path in `set_event_on_completion`**: - Checks `fence.value.load(Ordering::Acquire) >= value` before acquiring `fence.waiters.lock()`, avoiding mutex acquisition altogether for already-completed fence values (and drops the mutex before calling `set_event` when the re-check under the lock observes completion). 2. **Signal Win32 events outside `fence.waiters` mutex in `set()`**: - Atomically updates `fence.value` and extracts reached waiters under `fence.waiters.lock()` (with zero heap allocation when `waiters` is empty), releases the mutex, and calls `SetEvent` outside the lock so concurrent callers do not block on kernel event signaling. 3. **Concurrency regression test**: - Adds `concurrent_wait_and_signal_never_loses_a_wakeup` racing 128 `set_event_on_completion` registrations against concurrent `set` signals to verify zero lost wakeups. ## Verification - `cargo test -p victory-gpu --lib fence::tests` (default and `--features diagnostics`) - `cargo xtask policy` inside `third_party/victory`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:03:27 +00:00
github-bot closed this pull request 2026-11-26 18:35:14 +00:00
Author
Owner

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

Closing as duplicate: already included in #411.

**@⁠Lewandox** on GitHub · 2026-11-26 18:28 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/415#issuecomment-7200510420) Closing as duplicate: already included in #411.

Pull request closed

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