Title image: published under the hash of its patched bytes, not read back at every start #931

Open
0xkn0wh3r3 wants to merge 3 commits from upstream-pr/931 into main
0xkn0wh3r3 commented 2026-11-28 09:18:17 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 0xkn0wh3r3 on 2026-11-28T09:18:17Z.


Why

Every start spent time and memory on the title's image that it didn't need to:

  • The published copy was read back whole. publish::write_if_changed read the whole of victory-image-*.dll (115 MB for the title) just to compare it with the bytes it had just prepared.
  • prepare() copied its input once more (to_vec) before patching.
  • So at peak there were three 115 MB blocks and two full reads, with two single-threaded BLAKE3 passes on top.

What

The published image is keyed on the hash of its patched bytes (first commit):

  • Where it goes: <images>/<128-bit BLAKE3 of the patched bytes>/victory-image-<build>.dll.
  • When it's reused: a start that finds that file, with the right length and with the modified time stamped on it at publication, uses it without reading it.
  • The key is the patched bytes, ours and the switches' patches together, so a change to any patch publishes beside the old copy and can never be mistaken for it.
  • Damage is caught: a file written over or truncated since has another time or length, and is published again.
  • The file name is unchanged. It's the module's name, so logs, profiles and VICTORY_WRITE_SITES lists still match. Only the folder is new.
  • Several runners can still publish at once. Each stages its own file, sets the stamp, flushes to the disk (new here: main wrote the staging file without a flush), then renames. A rename refused because another runner published the same bytes first and has them mapped counts as success.
  • Old copies are cleaned up. The same name under other keys, and the copy older versions wrote straight in the folder, are removed once they are 60 s old. A mapped copy stays, since Windows won't delete it; it goes at the first start after it's let go. Other builds' images are never touched.
  • One less copy: prepare_owned(Vec<u8>) patches the bytes where they were read. The runner and the title's DLLs use it, and prepare(&[u8]) stays as a wrapper.

Both hashes run on several threads (second commit):

  • victory_loader::hash splits the input where BLAKE3's tree does (left_subtree_len), hashes each half as a subtree on its own thread (blake3::hazmat), and joins them.
  • Up to 8 threads, none for less than 4 MB. It gives the same hash as blake3::hash, with no new dependency.

Numbers

Publish step = read the exe, prepare, publish an image that's already there. The test binary padded to 115 MB stands in for the title. Warm cache, 9 runs per process, alternating rounds:

median per round peak private memory
main's way (read back and compare, to_vec) 95.4–102.4 ms 346 MB
keyed by hash, one thread 59.3–69.2 ms 116 MB
keyed by hash, threads 30.9–32.0 ms 116 MB

BLAKE3 of 115 MB on its own: 18.3 ms on one thread, 3.7 ms on 8 (hash::tests::bench_hash).

Tests

  • publish::tests:
    • an unchanged image isn't rewritten;
    • changed bytes publish a new image, and the old one goes;
    • a damaged (written over) or truncated image is replaced, even with the stamp put back;
    • two concurrent publishers both succeed and leave no staging file (stress-run 50 times);
    • a failed publication leaves nothing;
    • other names and non-key folders are left alone, and the copy from before keys is removed;
    • a mapped old copy stays and goes once it's let go.
  • prepare::tests::prepared_in_place_as_from_a_copy: prepare_owned gives the same bytes and hash as prepare.
  • hash::tests::the_same_hash_as_blake3s_own: compares against blake3::hash at every length around chunk and power-of-two boundaries, for 1–9 threads and several piece sizes. Also at a real size.
  • Benchmarks, all ignored: publish::tests::bench_publish_step and hash::tests::bench_hash.

CI steps run locally on this branch:

  • cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
  • The same with --all-features: passes.
  • cargo test --workspace --locked --no-fail-fast: passes. 1,134 passed, 0 failed, 51 ignored.

Clippy: the four findings that stop CI on main (Rust 1.98) is the same commit as in #816 and #819. Without it, main itself fails clippy. Drop it if main fixes them first.

Not covered:

  • Not yet tried with the real title exe or a game start.
  • No cold-cache or HDD measurement.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5538662010 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/931). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-28T09:18:17Z. --- ## Why Every start spent time and memory on the title's image that it didn't need to: - **The published copy was read back whole.** `publish::write_if_changed` read the whole of `victory-image-*.dll` (115 MB for the title) just to compare it with the bytes it had just prepared. - **`prepare()` copied its input once more** (`to_vec`) before patching. - **So at peak there were three 115 MB blocks and two full reads**, with two single-threaded BLAKE3 passes on top. ## What **The published image is keyed on the hash of its patched bytes** (first commit): - **Where it goes:** `<images>/<128-bit BLAKE3 of the patched bytes>/victory-image-<build>.dll`. - **When it's reused:** a start that finds that file, with the right length and with the modified time stamped on it at publication, uses it without reading it. - **The key is the patched bytes**, ours and the switches' patches together, so a change to any patch publishes beside the old copy and can never be mistaken for it. - **Damage is caught:** a file written over or truncated since has another time or length, and is published again. - **The file name is unchanged.** It's the module's name, so logs, profiles and `VICTORY_WRITE_SITES` lists still match. Only the folder is new. - **Several runners can still publish at once.** Each stages its own file, sets the stamp, flushes to the disk (new here: `main` wrote the staging file without a flush), then renames. A rename refused because another runner published the same bytes first and has them mapped counts as success. - **Old copies are cleaned up.** The same name under other keys, and the copy older versions wrote straight in the folder, are removed once they are 60 s old. A mapped copy stays, since Windows won't delete it; it goes at the first start after it's let go. Other builds' images are never touched. - **One less copy:** `prepare_owned(Vec<u8>)` patches the bytes where they were read. The runner and the title's DLLs use it, and `prepare(&[u8])` stays as a wrapper. **Both hashes run on several threads** (second commit): - `victory_loader::hash` splits the input where BLAKE3's tree does (`left_subtree_len`), hashes each half as a subtree on its own thread (`blake3::hazmat`), and joins them. - Up to 8 threads, none for less than 4 MB. It gives the same hash as `blake3::hash`, with no new dependency. ## Numbers Publish step = read the exe, prepare, publish an image that's already there. The test binary padded to 115 MB stands in for the title. Warm cache, 9 runs per process, alternating rounds: | | median per round | peak private memory | |---|---|---| | `main`'s way (read back and compare, `to_vec`) | 95.4–102.4 ms | 346 MB | | keyed by hash, one thread | 59.3–69.2 ms | 116 MB | | keyed by hash, threads | 30.9–32.0 ms | 116 MB | BLAKE3 of 115 MB on its own: 18.3 ms on one thread, 3.7 ms on 8 (`hash::tests::bench_hash`). ## Tests - `publish::tests`: - an unchanged image isn't rewritten; - changed bytes publish a new image, and the old one goes; - a damaged (written over) or truncated image is replaced, even with the stamp put back; - two concurrent publishers both succeed and leave no staging file (stress-run 50 times); - a failed publication leaves nothing; - other names and non-key folders are left alone, and the copy from before keys is removed; - a mapped old copy stays and goes once it's let go. - `prepare::tests::prepared_in_place_as_from_a_copy`: `prepare_owned` gives the same bytes and hash as `prepare`. - `hash::tests::the_same_hash_as_blake3s_own`: compares against `blake3::hash` at every length around chunk and power-of-two boundaries, for 1–9 threads and several piece sizes. Also at a real size. - Benchmarks, all ignored: `publish::tests::bench_publish_step` and `hash::tests::bench_hash`. **CI steps run locally on this branch:** - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - The same with `--all-features`: passes. - `cargo test --workspace --locked --no-fail-fast`: passes. 1,134 passed, 0 failed, 51 ignored. `Clippy: the four findings that stop CI on main (Rust 1.98)` is the same commit as in #816 and #819. Without it, `main` itself fails clippy. Drop it if `main` fixes them first. **Not covered:** - Not yet tried with the real title exe or a game start. - No cold-cache or HDD measurement.
Dukestar69 commented 2026-11-28 09:31:26 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-28T09:31:26Z.

Review: APPROVED


Tested locally merged onto main (63b902f).

  • Merge & Policy: Clean merge; cargo xtask policy passed (295 files ok).
  • Tests: cargo test -p victory-loader --lib passed (53 passed; 0 failed; 2 ignored, including hash::tests::the_same_hash_as_blake3s_own, publish::tests::an_unchanged_image_is_not_rewritten, changed_bytes_publish_a_new_image_and_remove_the_old, a_damaged_or_truncated_image_is_replaced, and prepare::tests::prepared_in_place_as_from_a_copy).
  • Workspace Check: cargo check -p victory succeeded cleanly with 0 warnings.

Nice startup speedup avoiding re-reading the published title image on every launch while maintaining full content-hash verification. LGTM.

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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6096980338 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/931#pullrequestreview-6096980338). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-28T09:31:26Z. **Review:** APPROVED --- Tested locally merged onto `main` (`63b902f`). - **Merge & Policy**: Clean merge; `cargo xtask policy` passed (`295 files ok`). - **Tests**: `cargo test -p victory-loader --lib` passed (`53 passed; 0 failed; 2 ignored`, including `hash::tests::the_same_hash_as_blake3s_own`, `publish::tests::an_unchanged_image_is_not_rewritten`, `changed_bytes_publish_a_new_image_and_remove_the_old`, `a_damaged_or_truncated_image_is_replaced`, and `prepare::tests::prepared_in_place_as_from_a_copy`). - **Workspace Check**: `cargo check -p victory` succeeded cleanly with 0 warnings. Nice startup speedup avoiding re-reading the published title image on every launch while maintaining full content-hash verification. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/931:upstream-pr/931'
git switch 'upstream-pr/931'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/931'
git switch 'upstream-pr/931'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/931'
git switch 'upstream-pr/931'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/931'
git switch 'main'
git merge --squash 'upstream-pr/931'
git switch 'main'
git merge --ff-only 'upstream-pr/931'
git switch 'main'
git merge 'upstream-pr/931'
git push origin 'main'
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
trustno1-coder/VIctory-NVIDIA!931
No description provided.