Guards: a waiter tries the guards' lock again a while before it sleeps (VICTORY_GUARD_SPIN=<us>, off by default) #3523
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!3523
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3523"
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?
@lexical-scope on GitHub · 2026-11-30 00:26 UTC · original
lexical-scope:pr-guard-spin→main· +40 −1 · 1 files · 1 commits · openWhat
guards()takes the guards' lock withtry_lock, and a thread that finds it held sleeps onlock()at once. WithVICTORY_GUARD_SPIN=<microseconds>(at most 1000) it first tries again for that long, then sleeps as before.Unset or
0: unchanged.Why
The guards' lock is held about 11 µs at a time, some 1,160 times a frame. A waiter that sleeps is woken through the scheduler, and threads that arrive meanwhile take the lock ahead of it, so a sleeping wait costs far more than a hold.
With 200 µs, in a diagnostics build (our own lock-timing lines, not part of this PR), 474 waits a frame had the lock by trying again and 20 slept for it after all.
Measured
RTX 3080 Ti, 24 logical processors, Windows 11, Series S,
-Dlss off, release build, same settings except the switch. Medians of the 5-second frame lines, split by draws per frame. Each cell is frame / preparing / waiting on the GPU, in ms:VICTORY_GUARD_SPIN=200Preparing (the submitting thread) was 5–10 ms shorter with the switch at every scene weight. Two more runs with it on, in other sessions, prepared in about the same time as the left column (37–40 / 48–49 / 54–56 ms).
The frame times vary more between sessions than this switch does. In one of those other runs with the switch on, frames took about as long as in the right column, while preparing still took as little time as on the left. So the fps lines above are one pair of runs, and the preparing times are the result.
Tests
cargo clippy -p victory-gpu --all-targets --locked, with and without--all-features: no warnings in the changed lines.cargo test -p victory-gpu --lib --locked: 921 passed; one fails, as it does onmainalready (shader_cache::tests::every_switch_of_the_translator_is_in_the_key:VICTORY_SCALAR_SPLITS is not read by the translator any more).--features diagnostics: 993 passed, the same failure, andcompose::tests::bgrx_plane_selects_a_typed_view(diagnostics only,compose.rs, not touched here).mainwith our other branch commits, release and diagnostics builds.🤖 Generated with Claude Code
@DoubleD17 on GitHub · 2026-11-30 03:37 UTC · original · edited 2026-11-30 09:56 UTC
We ran a test of this PR with
VICTORY_GUARD_SPIN=200on a CPU-bound machine (about 66 ms of CPU preparation per frame).No gain we can measure here: the controls alone spread over 9 ms, so a difference under about 5 ms is inside the noise. The picture was clean (0 defects in 160 frames).
One difference from your setup: 16 logical processors here against your 24, so fewer threads queue on the guards' lock at once, and the spin may have less to win.
Setup:
41adb551(only its own commits on top), against41adb551itself;41adb551spread through the session;Picture check: a burst of 10 captures a second at the end of each run (80 frames), looked at frame by frame.
AI Assisted
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.