Skip to content

victory: translate --cache and the pre-build say where their time went (slowest shaders and pipelines, library saves) - #2951

Open
0xkn0wh3r3 wants to merge 2 commits into
Marvisak:mainfrom
0xkn0wh3r3:tools/build-timing
Open

0xkn0wh3r3 wants to merge 2 commits into
Marvisak:mainfrom
0xkn0wh3r3:tools/build-timing

Conversation

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor

A warm-up of a title's shaders (translate --cache --pipelines) can take many minutes. Its output says how many shaders were translated and how many pipelines were made, but not whether the time went to our translator or the driver, nor which shaders.

What

At their end, both halves now print a time section:

  • translate --cache: the time spent translating containers, summed over the worker threads, and the 10 slowest by hash. Only containers translated now are counted, not cache hits.
  • The pipeline pre-build:
    • time translating each pipeline's shaders, or finding them in the cache;
    • time making host pipelines (the driver's compilation, or the library's lookup);
    • for each, the 10 slowest pipelines by key and shaders;
    • library saves: how many, how long, and how long the library was locked while being serialised. Pipelines being made wait to be stored meanwhile. The library is about 1.7 GB on NVIDIA and is saved every 20 s during a pre-build.

Prebuild::make_timed returns the two times, and victory_gpu::pipeline::library_saves reports the saves. What gets made doesn't change.

Why: it's the measurement to take before choosing between the open speed-ups for long warm-ups. Candidates are the translator's slow passes (#2662, #2640, #2657, #2665), smaller emitted programs (#2150, #2825), sharded library saves (#1653), and worker counts (#2752).

Tests

  • slowest::tests::it_sums_all_and_names_the_slowest: the totals are summed, the 10 slowest are kept in order, and only items that make the top 10 are named.
  • cargo test -p victory and -p victory-gpu --lib pipeline pass.
  • cargo clippy --locked -p victory -p victory-gpu --all-targets is clean, with and without --features diagnostics.

Not run on a title here: there are no game files on this machine. The report is meant to be read from a real warm-up's output.

A warm-up of a title's shaders can take many minutes, and nothing said
whether the time was ours or the driver's, nor which shaders. At their
end both now print a "time" section:

- translate --cache: the time translating containers (summed over the
  worker threads) and the 10 slowest by hash;
- the pre-build: the time translating pipelines' shaders (or finding
  them in the cache), the time making host pipelines (the driver's
  compilation, or the library's lookup), each with the 10 slowest
  pipelines by key and shaders, and the library saves: how many, how
  long, and how long the library was locked serialising (pipelines being
  made wait to be stored meanwhile; the library is about 1.7 GB on
  NVIDIA and saved every 20 s).

Prebuild::make_timed returns the two times; victory_gpu::pipeline::
library_saves the saves. Nothing changes in what is made.
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
With Marvisak#2907: the summary lines go through progress::say, and Marvisak#2951's time section follows them; the library save keeps Marvisak#2129's directory creation and staging files beside Marvisak#2951's timing.
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
Marvisak#2951's time sections (translations, pipelines' shaders, host pipelines, library saves) are printed as Marvisak#2907's summary lines are, so that a pre-build at run's start also has them in the progress window's log and the run's log.
@cloph-dsp

Copy link
Copy Markdown

Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup.

  • Diff against merge-base 842b0cb: 7 files, +187/-6. git diff --check flags the same trailing whitespace in README.md:17 (displayed. ).
  • Negative control: it_sums_all_and_names_the_slowest is absent from the base commit.
  • cargo test --locked -p victory --bin victory -- slowest::tests::it_sums_all_and_names_the_slowest --exact --quiet -> 1 passed, 14 filtered (CARGO_BUILD_JOBS=2).
  • Full binary tests: cargo test --locked -p victory --bin victory --quiet -> 15 passed, 0 failed.
  • Only a minor pre-existing warning in victory-hle.

AI-assisted (Hy4 flash).

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review and Windows 11 verification at head 19a68c592fe7 on main (63bcca43c6a0):

  • Code review (apps/victory/src/slowest.rs, crates/victory-gpu/src/pipeline/library.rs):
    • Slowest accumulates total_us and count lock-free via AtomicU64, locking kept: Mutex<Vec<(Duration, String)>> only for Top-10 entries and evaluating name: impl FnOnce() -> String lazily only when a duration enters the top 10 (zero string allocations on the fast path).
    • library::SAVES records save count, total time, and lock-hold time cleanly (skipping lock/counters when added == 0 && !prebuilt_changed && !USED_CHANGED; minor non-blocking note: if zeroed/Serialize returns Err inside the lock, the Timed drop guard still bumps SAVES[2] without bumping SAVES[0]/SAVES[1]). Prebuild::make_timed splits monotonic Instant translate vs create durations cleanly.
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 192 files ok; cargo clippy -p victory -p victory-gpu --all-targets -- -D warnings: 0 warnings
    • cargo test --locked -p victory: 19/19 passed (15 unit including it_sums_all_and_names_the_slowest + 4 integration)
    • victory-gpu --lib -- pipeline:: (RTX 5090, VICTORY_D3D12_DEBUG=1): 23/23 passed.

LGTM.

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: Slowest sums all durations but only formats names for entries that make the top-10 (locked vec, lazy FnOnce name). The pre-build timing split is clean — translated = first quiet dispatch, created = elapsed minus translated. SAVES[2] correctly measures only the locked serialize window via the Timed drop guard while SAVES[1] is the whole save including atomic write. translate --cache gates on translated+refused>0 and marks refused entries.

Marvisak commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (recommending a look, not approving). Thanks for taking the minor point. In 2a7976c, library::save (crates/victory-gpu/src/pipeline/library.rs) adds the time it held the lock to SAVES[2] only on the Serialize success path, and the Timed guard is gone. Early returns (failed zeroed or Serialize) no longer add lock time without a counted save. The rest is as reviewed before: apps/victory/src/slowest.rs keeps totals and the 10 slowest by name, Prebuild::make_timed splits translate time from create time, and nothing about what gets built changes.

CI: passing (check).


Generated by Claude Code

The time spent with the library's lock held is counted only for saves that serialise it, so SAVES[2] stays part of the time the counted saves took.
@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

Took the minor point in 2a7976c: library::save now adds the time it held the lock only for saves that serialise, so an early return (failed zeroed or Serialize) no longer adds to SAVES[2] without a counted save. The Timed guard is gone.

0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
# Conflicts:
#	crates/victory-gpu/src/pipeline/library.rs

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against origin/main (63bcca4):

  • cargo test -p victory -- --test-threads=1: 15 lib + 4 integration tests passed (including slowest::tests::it_sums_all_and_names_the_slowest).
  • cargo clippy -p victory --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

Cleanly reports timing totals and the slowest shaders/pipelines during translate --cache and pre-build.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and verified head 2a7976c2d29e57e0096f3bdd0fa9612190d685af (clean merge with origin/main 63bcca43) on Windows 11 x64 with NVIDIA GeForce RTX 5090 and D3D12 WARP (VICTORY_D3D12_DEBUG=1, Rust 1.98.1).

Code review

  • apps/victory/src/slowest.rs (L11-64): accumulates total_us and count via lock-free AtomicU64 (saturating as_micros() cleanly to u64::MAX), guards division by zero with count.max(1) so empty reports produce 0 in 0.0 s with no NaN, bounds retained memory to KEPT = 10 entries, and evaluates name lazily only when an entry enters the top 10.
  • crates/victory-gpu/src/pipeline.rs: Prebuild::make_timed (L668, inside #[cfg(windows)] impl Prebuild) and library_saves (L708, #[cfg(windows)]) preserve non-Windows #[cfg] hygiene and leave pipeline compilation/caching behavior and on-disk library format untouched.
  • crates/victory-gpu/src/pipeline/library.rs (L55, L343, L360-361): SAVES[2] now records lock-held serialization time only on the Serialize success path (avoiding inflated lock time on early error returns), and merges cleanly with #2646 with zero conflicts.
  • apps/victory/src/translate.rs (L340, L377, L435) and prebuild.rs (L227, L248, L287): cleanly exclude cache hits from translation timings and skip the time section when no work ran.

Verification

  • cargo xtask policy: 192 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): 0 warnings
  • cargo test --locked -p victory -- --test-threads=1: 19/19 passed (15 unit including slowest::tests::it_sums_all_and_names_the_slowest + 4 integration)
  • cargo test --locked -p victory-gpu --lib -- pipeline::: 23/23 passed (RTX 5090 default), 26/26 passed (RTX 5090 --features diagnostics + VICTORY_D3D12_DEBUG=1), 26/26 passed (WARP --features diagnostics + VICTORY_D3D12_DEBUG=1)
  • Additional local probe verified empty Slowest (no NaN), all-zero durations, Duration::MAX clamping, and 8-thread concurrent Slowest::add (8,000 items: exact total, exact count, top-10 sorted descending); combined #2951 + #2646 merge passed --all-features Clippy cleanly.

Clean, useful diagnostics; approving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants