Skip to content

perf(gpu): single-pass ask_once, sorted ahead lookup, ask_once_active skip, and merged Shadow copied/ranged lock - #1676

Open
qlfu wants to merge 1 commit into
trustno1-coder:mainfrom
qlfu:pr/watch-and-refresh-perf
Open

qlfu wants to merge 1 commit into
trustno1-coder:mainfrom
qlfu:pr/watch-and-refresh-perf

Conversation

@qlfu

@qlfu qlfu commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

What it changes

Removes redundant submitting-thread write-watch work and lock/atomic contention across watch, shadow, and host refresh flushes:

  • crates/victory-gpu/src/watch.rs:
    • Tracks ASK_ONCE_ACTIVE (AtomicBool mirror of Journal::kept) and exposes ask_once_active() so ask_ahead() / ask_ahead_done() and Batch::refresh_front / Batch::flush_all skip building, filtering (published), sorting, and discarding thousands of ranges on every flush while ask_once is already active.
    • Consolidates ask_once into a single pass over ranges (one published() filter, one sort, one Askings::hold_or_all, one journal_mut() lock) instead of running ask_ahead followed by a second full scan and ahead.clone() in ask_rest.
    • Keeps Journal::ahead sorted and merged into disjoint intervals and replaces linear j.ahead.iter().any(...) scans in nothing_new, writes, asked, ask_more, and ask_rest with O(log N) ahead_contains (partition_point).
    • Checks copied page bounds / zero-marks in nothing_new before taking JOURNAL.read().
    • Adds unit tests for ahead_contains parity and ask_once active-flag / sorted-ahead invariants.
  • crates/victory-gpu/src/shadow.rs:
    • Merges Shadow::ranged into CopiedPages under Shadow::copied (all callers already held copied's lock), removing a second mutex per buffer check/update.
    • Guards Shadow::update's self.pending.lock() and Vec allocation behind the existing lock-free self.has_pending.load(Acquire) check.
    • Skips watch::parts_written(&again_at) (and its JOURNAL.read()) in Shadow::copy_stale when again_at is empty.
    • Adds wide_each_chunks so parallel flush workers receive (from, to) ranges directly.
  • crates/victory-gpu/src/host.rs:
    • Skips building ranges: Vec<(usize, usize)> before watch::ask_ahead in Batch::refresh_front and Batch::flush_all when watch::ask_once_active() is true.
    • Uses wide_each_chunks in Batch::refresh_front and Batch::flush_all to flush FLUSHES[2] (nothing_new count) once per worker chunk instead of per buffer.

How it was tested

  • GPU and profile: RTX 4070 Ti 12 GB + Ryzen 7 5700X, Series X (game_scarlett_master.exe), 1440p DLSS Balanced, -NoFrameGenReady, VICTORY_PORT_CONSTANTS=1, VICTORY_WAIT_RESIDENT=textures, clean 90s gameplay runs (0 WARNs / 0 ERRORs).
  • Before (stack8v2 without this PR):
    • FPS: median 22.00 / mean 23.15 (p10 18.0, max 31.2), frame_times med 43.7 ms / mean 43.5 ms, >50 ms: 24.9%
    • Submitting thread sub_all: median 36.25 ms / mean 37.35 ms (watch 5.00 ms, refreshes 10.75 ms, ASYNC_SUBMIT worked 39.4 ms)
  • After (stack9 with this PR):
    • FPS: median 22.80 / mean 23.64 (p10 19.2, max 32.2), frame_times med 42.7 ms / mean 42.7 ms, >50 ms: 24.0%
    • Submitting thread sub_all: median 35.30 ms / mean 36.12 ms (-1.23 ms mean; watch 4.65 ms -7%, refreshes 10.55 ms, ASYNC_SUBMIT worked 37.05 ms -2.35 ms)
  • cargo clippy -p victory-gpu --lib --tests --locked (default & --all-features): 0 new warnings.
  • cargo test passed for the crates it touches: yes (551 passed; 0 failed in cargo test -p victory-gpu --lib --locked -- --test-threads=1).

Checked for overlap

… skip, merged Shadow ranged/copied lock, and chunk-batched refresh counters
@github-actions github-actions Bot added the pr-performance Pull request: makes it faster or use less memory label Nov 28, 2026
@github-actions github-actions Bot changed the title [pr-performance] perf(gpu): single-pass ask_once, sorted ahead lookup, ask_once_active skip, and merged Shadow copied/ranged lock perf(gpu): single-pass ask_once, sorted ahead lookup, ask_once_active skip, and merged Shadow copied/ranged lock Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request: makes it faster or use less memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant