loader: boot I/O — digest sidecar for the image cache, batched IAT VirtualProtect #3354

Open
borosf wants to merge 6 commits from upstream-pr/3354 into main
borosf commented 2026-11-26 20:07:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T20:07:33Z.


What

Two boot-time I/O costs in victory-loader, both measured synthetic-only (no game data):

  1. publish::write_if_changed re-read the whole cached image (~114 MB per exe/DLL, per boot) just to compare bytes. It now answers "already there" from a 32-byte blake3 sidecar written at publish time, plus a metadata length check (so a deleted image still republishes). The full read+compare remains only as the legacy fallback for caches from before sidecars, and it publishes the sidecar for next time.
  2. windows.rs write_slots did two VirtualProtect per IAT slot. It now groups slots by page, asks each page's protection once (VirtualQuery), merges consecutive same-protection pages into runs, and does one unprotect + one restore per run — splitting where protection changes (delay-load tables in .didat), so per-section protections are preserved exactly.

Claimed on #1633 (comment 7202184435).

Measurement (Windows 11 x64, Intel Arc B580 host, synthetic tempfile/VirtualAlloc only)

New tests print the numbers (cargo test -p victory-loader --locked -- --test-threads=1 --nocapture slots_tests publish):

64 MB cache hit: sidecar path 14.07ms, old read+compare 19.58ms   (warm page cache; cold cache pays the NVMe read on the old path, per DLL per boot)
5000 IAT slots: batched 710.3µs, per-slot 8.83ms                    (12.4x)

Correctness tests: sidecar hit does not rewrite (mtime unchanged); deleted image under a matching sidecar republishes; changed bytes republish and move the sidecar; legacy cache without sidecar falls back to read+compare and publishes the sidecar; 500 slots across 3 pages with mixed protections are all written and each page's original protection restored (incl. a PAGE_READONLY middle page forcing a run split).

Verification

  • cargo test -p victory-loader --locked --no-fail-fast — all targets ok (37+1+2+1 passed, 0 failed)
  • cargo clippy --workspace --all-targets --locked -- -D warnings and --all-features — clean
  • fmt gate: rustfmt --config-path rustfmt.toml --edition 2024 --check — windows.rs 0 hunks (baseline 0), publish.rs 1 hunk (baseline 2; only pre-existing hunks remain)
  • cargo xtask policy — 193 files ok

No game data used anywhere; synthetic tests only.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5516488286 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3354). Originally posted by [borosf](https://github.com/borosf) on 2026-11-26T20:07:33Z. --- ## What Two boot-time I/O costs in `victory-loader`, both measured synthetic-only (no game data): 1. **`publish::write_if_changed`** re-read the whole cached image (~114 MB per exe/DLL, per boot) just to compare bytes. It now answers "already there" from a 32-byte blake3 **sidecar** written at publish time, plus a metadata length check (so a deleted image still republishes). The full read+compare remains only as the legacy fallback for caches from before sidecars, and it publishes the sidecar for next time. 2. **`windows.rs write_slots`** did **two `VirtualProtect` per IAT slot**. It now groups slots by page, asks each page's protection once (`VirtualQuery`), merges consecutive same-protection pages into runs, and does one unprotect + one restore per run — splitting where protection changes (delay-load tables in `.didat`), so per-section protections are preserved exactly. Claimed on #1633 (comment 7202184435). ## Measurement (Windows 11 x64, Intel Arc B580 host, synthetic tempfile/VirtualAlloc only) New tests print the numbers (`cargo test -p victory-loader --locked -- --test-threads=1 --nocapture slots_tests publish`): ``` 64 MB cache hit: sidecar path 14.07ms, old read+compare 19.58ms (warm page cache; cold cache pays the NVMe read on the old path, per DLL per boot) 5000 IAT slots: batched 710.3µs, per-slot 8.83ms (12.4x) ``` Correctness tests: sidecar hit does not rewrite (mtime unchanged); deleted image under a matching sidecar republishes; changed bytes republish and move the sidecar; legacy cache without sidecar falls back to read+compare and publishes the sidecar; 500 slots across 3 pages with mixed protections are all written and each page's original protection restored (incl. a `PAGE_READONLY` middle page forcing a run split). ## Verification - `cargo test -p victory-loader --locked --no-fail-fast` — all targets ok (37+1+2+1 passed, 0 failed) - `cargo clippy --workspace --all-targets --locked -- -D warnings` and `--all-features` — clean - fmt gate: `rustfmt --config-path rustfmt.toml --edition 2024 --check` — windows.rs 0 hunks (baseline 0), publish.rs 1 hunk (baseline 2; only pre-existing hunks remain) - `cargo xtask policy` — 193 files ok No game data used anywhere; synthetic tests only.
AurumCarlos commented 2026-11-26 20:18:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T20:18:16Z.

Review: COMMENTED


The IAT batching looks right. The sidecar can end up describing a different image than the one on disk, though, and the fast path then trusts it:

  • The image is published by an atomic rename, but the sidecar is written afterwards as a separate, non-atomic step. The module explicitly supports two publishers of the same path at once. If P1 renames A, P2 renames B, and P1's write(sidecar, digest(A)) lands last, the cache holds image B with sidecar A. A later boot whose bytes are A then gets "already there" (digest matches, and length matches if A and B are the same size, which is common for re-prepared images) and runs with B. A crash between the rename and the sidecar write leaves the same mismatch.
  • A cheap fix: remove the old sidecar before renaming, and only trust a sidecar written after the rename, e.g. by also recording the image's length and mtime in it, or by naming the sidecar after the digest so it can't describe a different file.
<!-- greyfinch-sync:Marvisak/VIctory:review:6080052567 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3354#pullrequestreview-6080052567). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T20:18:16Z. **Review:** COMMENTED --- The IAT batching looks right. The sidecar can end up describing a different image than the one on disk, though, and the fast path then trusts it: - The image is published by an atomic rename, but the sidecar is written afterwards as a separate, non-atomic step. The module explicitly supports two publishers of the same path at once. If P1 renames A, P2 renames B, and P1's `write(sidecar, digest(A))` lands last, the cache holds image B with sidecar A. A later boot whose bytes are A then gets "already there" (digest matches, and length matches if A and B are the same size, which is common for re-prepared images) and runs with B. A crash between the rename and the sidecar write leaves the same mismatch. - A cheap fix: remove the old sidecar before renaming, and only trust a sidecar written after the rename, e.g. by also recording the image's length and mtime in it, or by naming the sidecar after the digest so it can't describe a different file.
borosf commented 2026-11-26 20:34:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T20:34:24Z.


Fixed at 9f8174f — exactly the race you described. Publishers of one path are now serialized with a per-image lock file (LockFileEx on .{name}.lock, released when the handle closes, so a crashed publisher doesn't keep the cache locked), and the sidecar is removed before the atomic rename and written after it. Invariant: a sidecar on disk always describes the file on disk; a crash between rename and sidecar write leaves no sidecar, and the next boot takes the full read+compare fallback. The fast path itself is unchanged (sidecar digest + length match).

Regression test concurrent_publishers_keep_the_sidecar_matching_the_file: 4 threads × 50 alternating publishes; after each, if the file is unchanged across the check, a present sidecar must equal the file's digest. (The first version of that assert raced with publishers mid-rename; it now only asserts when the file is stable across both reads.)

Verification at 9f8174f (Windows 11, B580): cargo test -p victory-loader --locked --no-fail-fast all ok (38 lib tests incl. the race test); workspace clippy clean with -D warnings default and --all-features; cargo xtask policy ok; fmt gate 0 hunks on publish.rs; Cargo.lock unchanged (feature-only addition of windows-sys Win32_Storage_FileSystem/Win32_System_IO). Synthetic tests only; no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7202841565 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3354#issuecomment-7202841565). Originally posted by [borosf](https://github.com/borosf) on 2026-11-26T20:34:24Z. --- Fixed at `9f8174f` — exactly the race you described. Publishers of one path are now serialized with a per-image lock file (`LockFileEx` on `.{name}.lock`, released when the handle closes, so a crashed publisher doesn't keep the cache locked), and the sidecar is **removed before the atomic rename and written after it**. Invariant: a sidecar on disk always describes the file on disk; a crash between rename and sidecar write leaves no sidecar, and the next boot takes the full read+compare fallback. The fast path itself is unchanged (sidecar digest + length match). Regression test `concurrent_publishers_keep_the_sidecar_matching_the_file`: 4 threads × 50 alternating publishes; after each, if the file is unchanged across the check, a present sidecar must equal the file's digest. (The first version of that assert raced with publishers mid-rename; it now only asserts when the file is stable across both reads.) Verification at `9f8174f` (Windows 11, B580): `cargo test -p victory-loader --locked --no-fail-fast` all ok (38 lib tests incl. the race test); workspace clippy clean with `-D warnings` default and `--all-features`; `cargo xtask policy` ok; fmt gate 0 hunks on publish.rs; `Cargo.lock` unchanged (feature-only addition of windows-sys `Win32_Storage_FileSystem`/`Win32_System_IO`). Synthetic tests only; no game data.
borosf commented 2026-11-26 20:56:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T20:56:31Z.


CI caught a real one at 9f8174f: the sidecar was written with plain fs::write (truncate-then-write), so a concurrent reader saw a torn/empty digest (left: []), and the race test itself could fail its reads with AccessDenied while another publisher renamed over the file. Fixed at ad0fb99:

  • the sidecar now goes through its own staging file + atomic rename (write_sidecar), so readers only ever see a complete old or new digest;
  • the race test only asserts when all three reads succeed (a concurrent rename can fail them transiently).

Re-verified at ad0fb99 (Windows 11, B580): the race test passes 5/5 runs at --test-threads=8 (the CI condition), full loader suite ok, workspace clippy clean -D warnings default + --all-features, fmt gate at baseline (2 hunks), cargo xtask policy ok. Synthetic tests only; no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203227223 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3354#issuecomment-7203227223). Originally posted by [borosf](https://github.com/borosf) on 2026-11-26T20:56:31Z. --- CI caught a real one at `9f8174f`: the sidecar was written with plain `fs::write` (truncate-then-write), so a concurrent reader saw a torn/empty digest (`left: []`), and the race test itself could fail its reads with AccessDenied while another publisher renamed over the file. Fixed at `ad0fb99`: - the sidecar now goes through its own staging file + atomic rename (`write_sidecar`), so readers only ever see a complete old or new digest; - the race test only asserts when all three reads succeed (a concurrent rename can fail them transiently). Re-verified at `ad0fb99` (Windows 11, B580): the race test passes 5/5 runs at `--test-threads=8` (the CI condition), full loader suite ok, workspace clippy clean `-D warnings` default + `--all-features`, fmt gate at baseline (2 hunks), `cargo xtask policy` ok. Synthetic tests only; no game data.
fuzeofficlal commented 2026-11-26 21:21:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:21:37Z.

Review: CHANGES_REQUESTED


Moving sidecar writes to staging + rename (write_sidecar in ad0fb998) cleanly fixes torn/truncated sidecar reads, and windows.rs's batched write_slots plus all 38+4 victory-loader tests and clippy checks pass. However, two concrete edge cases in crates/victory-loader/src/publish.rs still allow a stale .blake3 sidecar to survive beside a newer image of the same length, causing a subsequent write_if_changed call to hit the fast path and silently serve the wrong image:

  1. Unlocked legacy-fallback sidecar write races with publish_lock (crates/victory-loader/src/publish.rs:123-128):

    if std::fs::read(path).is_ok_and(|existing| existing == bytes) {
        write_sidecar(path, &digest);
        return Ok(());
    }
    

    This fallback runs completely outside publish_lock. If path holds image A with no sidecar (either a legacy cache or the window after another publisher removes the sidecar at line 142), publisher 1 can read A at line 123, pause while publisher 2 acquires publish_lock, renames B over path, publishes hash(B), and releases the lock, and then publisher 1's write_sidecar(path, &digest) at line 126 atomically overwrites the sidecar with hash(A).

    • Reproduced live on Windows at ad0fb998 with two concurrent threads publishing 32 MiB images A (0x11) and B (0x22): disk ended with B (0x22) beside sidecar blake3(A), and a subsequent write_if_changed(&path, &a) returned Ok(()) via the fast path while leaving B (0x22) on disk.
  2. Ignoring non-NotFound errors on remove_file(sidecar) (crates/victory-loader/src/publish.rs:142, 149):

    let _ = std::fs::remove_file(sidecar(path));
    

    If an external handle (e.g., an antivirus scanner or indexer without FILE_SHARE_DELETE | FILE_SHARE_WRITE) keeps the sidecar open while write_if_changed publishes B, remove_file fails with ERROR_SHARING_VIOLATION and is silently discarded, rename(&staging, path) replaces the image with B, and write_sidecar's rename(&staging, &side) at line 149 also fails silently.

    • Reproduced live on Windows at ad0fb998: holding .locked.bin.blake3 open with GENERIC_READ + FILE_SHARE_READ, write_if_changed(&path, &b) returned Ok(()) with B (0xbb) on disk and blake3(A) still in the sidecar; a subsequent write_if_changed(&path, &a) then hit the fast path and silently left B (0xbb) on disk.

Suggested fix:

  • In the legacy fallback branch (L123-128), acquire publish_lock(path)? before re-checking path (or only backfill the sidecar under _lock after confirming path still matches bytes).
  • At line 142, propagate any remove_file(sidecar(path)) error other than ErrorKind::NotFound (cleaning up staging on error) before renaming staging over path, so the invariant "whenever a sidecar exists, it describes the file on disk" holds unconditionally.
<!-- greyfinch-sync:Marvisak/VIctory:review:6080585015 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3354#pullrequestreview-6080585015). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T21:21:37Z. **Review:** CHANGES_REQUESTED --- Moving sidecar writes to staging + rename (`write_sidecar` in `ad0fb998`) cleanly fixes torn/truncated sidecar reads, and `windows.rs`'s batched `write_slots` plus all 38+4 `victory-loader` tests and `clippy` checks pass. However, two concrete edge cases in `crates/victory-loader/src/publish.rs` still allow a stale `.blake3` sidecar to survive beside a newer image of the same length, causing a subsequent `write_if_changed` call to hit the fast path and silently serve the wrong image: 1. **Unlocked legacy-fallback sidecar write races with `publish_lock` (`crates/victory-loader/src/publish.rs:123-128`)**: ```rust if std::fs::read(path).is_ok_and(|existing| existing == bytes) { write_sidecar(path, &digest); return Ok(()); } ``` This fallback runs completely outside `publish_lock`. If `path` holds image `A` with no sidecar (either a legacy cache or the window after another publisher removes the sidecar at line 142), publisher 1 can read `A` at line 123, pause while publisher 2 acquires `publish_lock`, renames `B` over `path`, publishes `hash(B)`, and releases the lock, and then publisher 1's `write_sidecar(path, &digest)` at line 126 atomically overwrites the sidecar with `hash(A)`. - **Reproduced live on Windows at `ad0fb998`** with two concurrent threads publishing 32 MiB images `A` (`0x11`) and `B` (`0x22`): disk ended with `B` (`0x22`) beside sidecar `blake3(A)`, and a subsequent `write_if_changed(&path, &a)` returned `Ok(())` via the fast path while leaving `B` (`0x22`) on disk. 2. **Ignoring non-`NotFound` errors on `remove_file(sidecar)` (`crates/victory-loader/src/publish.rs:142, 149`)**: ```rust let _ = std::fs::remove_file(sidecar(path)); ``` If an external handle (e.g., an antivirus scanner or indexer without `FILE_SHARE_DELETE | FILE_SHARE_WRITE`) keeps the sidecar open while `write_if_changed` publishes `B`, `remove_file` fails with `ERROR_SHARING_VIOLATION` and is silently discarded, `rename(&staging, path)` replaces the image with `B`, and `write_sidecar`'s `rename(&staging, &side)` at line 149 also fails silently. - **Reproduced live on Windows at `ad0fb998`**: holding `.locked.bin.blake3` open with `GENERIC_READ` + `FILE_SHARE_READ`, `write_if_changed(&path, &b)` returned `Ok(())` with `B` (`0xbb`) on disk and `blake3(A)` still in the sidecar; a subsequent `write_if_changed(&path, &a)` then hit the fast path and silently left `B` (`0xbb`) on disk. **Suggested fix**: - In the legacy fallback branch (`L123-128`), acquire `publish_lock(path)?` before re-checking `path` (or only backfill the sidecar under `_lock` after confirming `path` still matches `bytes`). - At line 142, propagate any `remove_file(sidecar(path))` error other than `ErrorKind::NotFound` (cleaning up `staging` on error) before renaming `staging` over `path`, so the invariant *"whenever a sidecar exists, it describes the file on disk"* holds unconditionally.
borosf commented 2026-11-26 21:40:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T21:40:08Z.


Both fixed in 1f8da55 (on top of ad0fb99). Thank you for reproducing them — both reproduced here too.

1. Legacy fallback sidecar write raced with publish_lock. The read-back now happens inside the same critical section as the remove/rename/write-after: write_if_changed stages the bytes, takes publish_lock(path), and only then does the read-back-and-backfill. A backfill can no longer land after another publisher replaced the image, because it cannot run while that publisher holds the lock.

2. remove_file(sidecar) errors are no longer dropped. A sidecar that cannot be removed (e.g. ERROR_SHARING_VIOLATION from a reader without FILE_SHARE_DELETE) now stops the publication before the rename: the staging file is removed and the error is returned. The image and its sidecar are left matching, and the next attempt retries.

Regression tests, each verified to fail on ad0fb99 and pass on 1f8da55:

  • a_legacy_sidecar_backfill_waits_for_the_publishers_lock: holds publish_lock while a publisher backfills a legacy cache; asserts the sidecar does not appear until the lock is released. Fails on ad0fb99 (sidecar appears while the lock is held).
  • a_sidecar_that_cannot_be_removed_stops_the_publish: publishes A, opens the sidecar with GENERIC_READ | FILE_SHARE_READ, publishes B; asserts an error, and that the image still holds A with sidecar blake3(A). Fails on ad0fb99 (returns Ok(())' with B on disk).

Local verification (Windows 11 x64, Arc B580): cargo test -p victory-loader --lib --locked 40 passed / 0 failed (six in publish::tests); cargo clippy -p victory-loader --all-targets -- -D warnings clean, and with --all-features; cargo xtask policy 191 files ok; rustfmt --edition 2024 --check hunk parity with origin/main (2 = 2). Synthetic files only, no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203947237 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3354#issuecomment-7203947237). Originally posted by [borosf](https://github.com/borosf) on 2026-11-26T21:40:08Z. --- Both fixed in 1f8da55 (on top of ad0fb99). Thank you for reproducing them — both reproduced here too. **1. Legacy fallback sidecar write raced with `publish_lock`.** The read-back now happens inside the same critical section as the remove/rename/write-after: `write_if_changed` stages the bytes, takes `publish_lock(path)`, and only then does the read-back-and-backfill. A backfill can no longer land after another publisher replaced the image, because it cannot run while that publisher holds the lock. **2. `remove_file(sidecar)` errors are no longer dropped.** A sidecar that cannot be removed (e.g. `ERROR_SHARING_VIOLATION` from a reader without `FILE_SHARE_DELETE`) now stops the publication before the rename: the staging file is removed and the error is returned. The image and its sidecar are left matching, and the next attempt retries. Regression tests, each verified to fail on ad0fb99 and pass on 1f8da55: - `a_legacy_sidecar_backfill_waits_for_the_publishers_lock`: holds `publish_lock` while a publisher backfills a legacy cache; asserts the sidecar does not appear until the lock is released. Fails on ad0fb99 (sidecar appears while the lock is held). - `a_sidecar_that_cannot_be_removed_stops_the_publish`: publishes A, opens the sidecar with `GENERIC_READ | FILE_SHARE_READ`, publishes B; asserts an error, and that the image still holds A with sidecar `blake3(A)`. Fails on ad0fb99 (returns `Ok(())'` with B on disk). Local verification (Windows 11 x64, Arc B580): `cargo test -p victory-loader --lib --locked` 40 passed / 0 failed (six in `publish::tests`); `cargo clippy -p victory-loader --all-targets -- -D warnings` clean, and with `--all-features`; `cargo xtask policy` 191 files ok; `rustfmt --edition 2024 --check` hunk parity with origin/main (2 = 2). Synthetic files only, no game data.
fuzeofficlal commented 2026-11-26 22:00:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:00:30Z.

Review: APPROVED


Both stale-sidecar edge cases from the previous review are cleanly fixed in 1f8da553:

  • The legacy read-back and sidecar backfill (crates/victory-loader/src/publish.rs:138-145) now executes under publish_lock(path)?, cleaning up staging before returning, so it can no longer overwrite a newer publisher's sidecar.
  • std::fs::remove_file(sidecar(path)) (publish.rs:148-155) now propagates any error other than ErrorKind::NotFound (removing staging and aborting before the rename), preserving the on-disk invariant when an external handle holds the sidecar without delete sharing.

Verification on Windows against origin/main (63bcca43):

  • cargo xtask policy: ok (191 files ok)
  • cargo clippy --locked -p victory-loader --all-targets -- -D warnings (default and --all-features): clean
  • cargo test --locked -p victory-loader --no-fail-fast: 40 lib + 4 integration tests passed, including a_legacy_sidecar_backfill_waits_for_the_publishers_lock and a_sidecar_that_cannot_be_removed_stops_the_publish (5,000 IAT slots: 461.6 µs batched vs 18.23 ms per-slot; 64 MB cache hit: 6.93 ms vs 17.72 ms)
  • Re-ran the 32 MiB concurrent legacy-vs-publisher race probe across 6 rounds: 6/6 passed with disk bytes and .blake3 sidecar matching on every round.
<!-- greyfinch-sync:Marvisak/VIctory:review:6080937541 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3354#pullrequestreview-6080937541). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T22:00:30Z. **Review:** APPROVED --- Both stale-sidecar edge cases from the previous review are cleanly fixed in `1f8da553`: - The legacy read-back and sidecar backfill (`crates/victory-loader/src/publish.rs:138-145`) now executes under `publish_lock(path)?`, cleaning up `staging` before returning, so it can no longer overwrite a newer publisher's sidecar. - `std::fs::remove_file(sidecar(path))` (`publish.rs:148-155`) now propagates any error other than `ErrorKind::NotFound` (removing `staging` and aborting before the rename), preserving the on-disk invariant when an external handle holds the sidecar without delete sharing. Verification on Windows against `origin/main` (`63bcca43`): - `cargo xtask policy`: ok (`191 files ok`) - `cargo clippy --locked -p victory-loader --all-targets -- -D warnings` (default and `--all-features`): clean - `cargo test --locked -p victory-loader --no-fail-fast`: 40 lib + 4 integration tests passed, including `a_legacy_sidecar_backfill_waits_for_the_publishers_lock` and `a_sidecar_that_cannot_be_removed_stops_the_publish` (5,000 IAT slots: 461.6 µs batched vs 18.23 ms per-slot; 64 MB cache hit: 6.93 ms vs 17.72 ms) - Re-ran the 32 MiB concurrent legacy-vs-publisher race probe across 6 rounds: 6/6 passed with disk bytes and `.blake3` sidecar matching on every round.
farhankhan8571811-star commented 2026-11-27 19:15:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by farhankhan8571811-star on 2026-11-27T19:15:31Z.


A data point that may be useful here, from a separate local change that I'm not submitting:

run.rs reads the exe, and victory_loader::prepare copies it before patching, so it is held twice during preparation. I tried patching the read buffer in place (prepare_owned(Vec<u8>), with the info and hash taken before the first write). Measured on synthetic PEs of 32–256 MB, baseline 63bcca4 vs that change, read + prepare + load, Windows 11, release builds:

  • about 0.4 ms per MB less (114 MB: ~180 → ~130 ms with a warm image cache);
  • peak private memory halved with a cold image cache (114 MB: 218.5 → 110 MiB);
  • with a warm cache the peak is unchanged (218.5 MiB both), because write_if_changed reads the published copy back while the prepared bytes are still alive.

That warm-cache read-back is what this PR replaces, so the two changes affect the same startup peak. I have not measured them together and am not claiming a combined effect.

Limitations: synthetic fixtures only (no game files), one laptop (Ryzen 7 7445HS, 16 GB), 5–12 runs per case, and noisy cold-cache times from the 114 MB disk write. If it would help once this lands, I can re-measure on top of it.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7226347779 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3354#issuecomment-7226347779). Originally posted by [farhankhan8571811-star](https://github.com/farhankhan8571811-star) on 2026-11-27T19:15:31Z. --- A data point that may be useful here, from a separate local change that I'm not submitting: `run.rs` reads the exe, and `victory_loader::prepare` copies it before patching, so it is held twice during preparation. I tried patching the read buffer in place (`prepare_owned(Vec<u8>)`, with the info and hash taken before the first write). Measured on synthetic PEs of 32–256 MB, baseline `63bcca4` vs that change, read + prepare + load, Windows 11, release builds: - about 0.4 ms per MB less (114 MB: ~180 → ~130 ms with a warm image cache); - peak private memory halved with a cold image cache (114 MB: 218.5 → 110 MiB); - with a warm cache the peak is unchanged (218.5 MiB both), because `write_if_changed` reads the published copy back while the prepared bytes are still alive. That warm-cache read-back is what this PR replaces, so the two changes affect the same startup peak. I have not measured them together and am not claiming a combined effect. Limitations: synthetic fixtures only (no game files), one laptop (Ryzen 7 7445HS, 16 GB), 5–12 runs per case, and noisy cold-cache times from the 114 MB disk write. If it would help once this lands, I can re-measure on top of it. AI-assisted (Claude Code).
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/3354:upstream-pr/3354'
git switch 'upstream-pr/3354'

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/3354'
git switch 'upstream-pr/3354'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3354'
git switch 'upstream-pr/3354'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3354'
git switch 'main'
git merge --squash 'upstream-pr/3354'
git switch 'main'
git merge --ff-only 'upstream-pr/3354'
git switch 'main'
git merge 'upstream-pr/3354'
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
Marvisak/VIctory!3354
No description provided.