perf: read the clock only for submission steps whose time is summed #279

Closed
Skyfrye wants to merge 2 commits from upstream-pr/279 into main
Skyfrye commented 2026-11-26 00:13:06 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Skyfrye on 2026-11-26T00:13:06Z.


Draft: the in-game A/B is pending (the change and its test are done; a measured run of the world with and without it is not).

Change

HostList::run_deferred (crates/victory-gpu/src/host.rs) read the clock (Instant::now) before every submission-time step of every list. Only two kinds of step use that time:

  • the title memory copies (Step::Copy, Step::Fill), summed into PREPARING[0] for the frame line;
  • with diagnostics, the title's work run at submission (Step::Run, Step::Host), summed into RunUs.

The others (Refresh, GpuWrite, Texture) only note what to do and continue before the time is used; they are most of a submission's steps. The clock is now read only for the first two (timed), and micros_since gives 0 where it was not read.

Where this comes from: a 30 s Nsight Systems capture of the world (release build of main at 3e258c8, launcher fast set, 263 frames). On the title's submitting thread, which spends 48 % of the time on the CPU in queue::execute, the innermost engine frame was Instant::now called from Host::submit (where run_deferred is inlined) on 2.8 % of the timer samples, and Instant::elapsed on 0.2 %. One QueryPerformanceCounter call measured 19 ns on this machine, so that is on the order of a million clock reads a second.

The frame line's sums do not change: the steps that were summed still are, with the same start and end.

Linked issue: none.

Verification

Windows 11 26300, Rust 1.98.1 (MSVC), on upstream main at 578098b, from third_party/victory:

cargo build --locked --release -p victory                              -> Finished, no new warning
cargo build --locked --profile diag -p victory --features diagnostics  -> Finished, no new warning
cargo test --locked -p victory-gpu --lib -- host::tests::only_summed_steps_read_the_clock -> 1 passed
cargo test --locked -p victory-gpu --lib                               -> 184 passed, 3 failed, 3 ignored

The 3 failures are the same on main without this change (183 passed, 3 failed): descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots, indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others.

New test only_summed_steps_read_the_clock: the copies are timed, the title's work only with diagnostics, and an unread clock counts 0 µs. (Refresh, GpuWrite and Texture need host objects made on a device; they take the false arm of the same match.) Without this change the test does not build, since timed and micros_since are new.

Pending: an A/B in the world (frame time; the submitting thread's share in Instant::now in a profile).

Oracle and test data

No game file. The profile numbers come from my own capture of my copy of the game; no game code, address or dump is in this PR.

Checklist

  • The PR covers a single reviewable behaviour (the clock is read only for steps whose time is summed).
  • A test fails without this change and passes with it (it does not build without it).
  • The commands and results of each check are given above (the in-game A/B is pending, said above).
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Nothing unimplemented here.)
  • README: not touched.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: engine function names from a profile of the engine; no title code.
  • Code taken from another project: none.

AI assistance: written with Claude Code. Claude Opus 5.5 read the Nsight Systems capture, wrote the change and its test, and wrote this description.

🤖 Generated with Claude Code

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5501477373 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/279). Originally posted by [Skyfrye](https://github.com/Skyfrye) on 2026-11-26T00:13:06Z. --- **Draft: the in-game A/B is pending** (the change and its test are done; a measured run of the world with and without it is not). ## Change `HostList::run_deferred` (`crates/victory-gpu/src/host.rs`) read the clock (`Instant::now`) before every submission-time step of every list. Only two kinds of step use that time: - the title memory copies (`Step::Copy`, `Step::Fill`), summed into `PREPARING[0]` for the frame line; - with `diagnostics`, the title's work run at submission (`Step::Run`, `Step::Host`), summed into `RunUs`. The others (`Refresh`, `GpuWrite`, `Texture`) only note what to do and `continue` before the time is used; they are most of a submission's steps. The clock is now read only for the first two (`timed`), and `micros_since` gives 0 where it was not read. Where this comes from: a 30 s Nsight Systems capture of the world (release build of `main` at `3e258c8`, launcher fast set, 263 frames). On the title's submitting thread, which spends 48 % of the time on the CPU in `queue::execute`, the innermost engine frame was `Instant::now` called from `Host::submit` (where `run_deferred` is inlined) on 2.8 % of the timer samples, and `Instant::elapsed` on 0.2 %. One `QueryPerformanceCounter` call measured 19 ns on this machine, so that is on the order of a million clock reads a second. The frame line's sums do not change: the steps that were summed still are, with the same start and end. Linked issue: none. ## Verification Windows 11 26300, Rust 1.98.1 (MSVC), on upstream `main` at `578098b`, from `third_party/victory`: ``` cargo build --locked --release -p victory -> Finished, no new warning cargo build --locked --profile diag -p victory --features diagnostics -> Finished, no new warning cargo test --locked -p victory-gpu --lib -- host::tests::only_summed_steps_read_the_clock -> 1 passed cargo test --locked -p victory-gpu --lib -> 184 passed, 3 failed, 3 ignored ``` The 3 failures are the same on `main` without this change (183 passed, 3 failed): `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots`, `indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others`. New test `only_summed_steps_read_the_clock`: the copies are timed, the title's work only with diagnostics, and an unread clock counts 0 µs. (`Refresh`, `GpuWrite` and `Texture` need host objects made on a device; they take the `false` arm of the same `match`.) Without this change the test does not build, since `timed` and `micros_since` are new. Pending: an A/B in the world (frame time; the submitting thread's share in `Instant::now` in a profile). ## Oracle and test data No game file. The profile numbers come from my own capture of my copy of the game; no game code, address or dump is in this PR. ## Checklist - [x] The PR covers a single reviewable behaviour (the clock is read only for steps whose time is summed). - [x] A test fails without this change and passes with it (it does not build without it). - [x] The commands and results of each check are given above (the in-game A/B is pending, said above). - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Nothing unimplemented here.) - [x] README: not touched. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: engine function names from a profile of the engine; no title code. - [x] Code taken from another project: none. AI assistance: written with Claude Code. Claude Opus 5.5 read the Nsight Systems capture, wrote the change and its test, and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
KainanP commented 2026-11-26 10:32:24 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-26T10:32:24Z.


Test report for #279 on three adapters.

Merges cleanly onto current main. Setup: current origin/main (c4c93bd) merged with this PR, Windows 11, cargo test --locked in third_party/victory. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is --features diagnostics + VICTORY_D3D12_WARP=1. victory-gpu runs with --test-threads=1.

victory-gpu --lib main main + #279
RTX 4060 Laptop 183 passed, main's 3 failed 184 passed, main's 3 failed
Intel UHD 183 passed, main's 3 failed 184 passed, main's 3 failed
WARP 196 passed, main's 3 failed 197 passed, main's 3 failed

"main's 3" = descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots, indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others. They fail on all three adapters on main too. only_summed_steps_read_the_clock passes everywhere, both without and with diagnostics (WARP build). No new failure.

Note: timed matches every Step variant explicitly, so a new variant forces a decision. That's good. (#254 changes Step::Texture(_) to two fields, so whichever merges second needs Step::Texture(..) here.)

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7189500388 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/279#issuecomment-7189500388). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T10:32:24Z. --- Test report for #279 on three adapters. Merges cleanly onto current main. Setup: current `origin/main` (c4c93bd) merged with this PR, Windows 11, `cargo test --locked` in `third_party/victory`. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is `--features diagnostics` + `VICTORY_D3D12_WARP=1`. victory-gpu runs with `--test-threads=1`. | `victory-gpu --lib` | main | main + #279 | |---|---|---| | RTX 4060 Laptop | 183 passed, main's 3 failed | 184 passed, main's 3 failed | | Intel UHD | 183 passed, main's 3 failed | 184 passed, main's 3 failed | | WARP | 196 passed, main's 3 failed | 197 passed, main's 3 failed | "main's 3" = `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots`, `indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others`. They fail on all three adapters on main too. `only_summed_steps_read_the_clock` passes everywhere, both without and with `diagnostics` (WARP build). No new failure. Note: `timed` matches every `Step` variant explicitly, so a new variant forces a decision. That's good. (#254 changes `Step::Texture(_)` to two fields, so whichever merges second needs `Step::Texture(..)` here.) _AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this._
Skyfrye commented 2026-11-26 13:06:05 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Skyfrye on 2026-11-26T13:06:05Z.


Rebased on main (8ed1109), plus one commit, bf7196b. It covers the timing of the same steps:

  • A run of upload fills is now timed once. That's some 9,700 fills a frame in the world, each under a microsecond; before, each read the clock twice and was counted as 0 µs.
  • A title copy is timed from after the flush that precedes it. The refreshes in that flush already count their own time.

The test only_summed_steps_read_the_clock covers FillTimer (cargo test --locked -p victory-gpu --lib only_summed_steps_read_the_clock -> 1 passed). The release build has no new warning. It was in the stacked game run described in #360: picture correct, no exception.

The fill timing comes from Antigravity (gemini-4-neon-medium), commit 22d77e4 of a local branch, ported by Claude Opus 5.5. A run of fills here also ends at a shader-write or texture step, because those do refresh work that is timed elsewhere.

🤖 Generated with Claude Code

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7192875929 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/279#issuecomment-7192875929). Originally posted by [Skyfrye](https://github.com/Skyfrye) on 2026-11-26T13:06:05Z. --- Rebased on `main` (8ed1109), plus one commit, bf7196b. It covers the timing of the same steps: - A run of upload fills is now timed once. That's some 9,700 fills a frame in the world, each under a microsecond; before, each read the clock twice and was counted as 0 µs. - A title copy is timed from after the flush that precedes it. The refreshes in that flush already count their own time. The test `only_summed_steps_read_the_clock` covers `FillTimer` (`cargo test --locked -p victory-gpu --lib only_summed_steps_read_the_clock` -> 1 passed). The release build has no new warning. It was in the stacked game run described in #360: picture correct, no exception. The fill timing comes from Antigravity (gemini-4-neon-medium), commit 22d77e4 of a local branch, ported by Claude Opus 5.5. A run of fills here also ends at a shader-write or texture step, because those do refresh work that is timed elsewhere. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LooperSalty commented 2026-11-27 15:39:54 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T15:39:54Z.


Closing as stale: this draft has been inactive for more than 24 hours and no longer applies cleanly to main (merge conflicts). Feel free to reopen after a rebase on current main and a fresh measurement of the clock-read change.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7222332463 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/279#issuecomment-7222332463). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T15:39:54Z. --- Closing as stale: this draft has been inactive for more than 24 hours and no longer applies cleanly to main (merge conflicts). Feel free to reopen after a rebase on current main and a fresh measurement of the clock-read change.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LooperSalty/AnyXboxX!279
No description provided.