Files: read the game's archives through the Windows file cache (faster loading) #941

Manually merged
github merged 2 commits from github-bot/gh-941 into main 2026-11-29 08:22:16 +00:00 AGit
Owner

@⁠aidanthehorrible on GitHub · 2026-11-28 09:29 UTC · original
aidanthehorrible:pr/file-buffered → main · +161 −0 · 1 files · 2 commits · merged 2026-11-29 08:16 UTC

What

The title opens each of its archives twice. The second open uses FILE_FLAG_NO_BUFFERING (63 of the 127 opens in a run). At loading it then reads them in about 80,000 small synchronous ReadFile calls, one at a time. Most calls are 4 KiB or less.

The console's storage serves reads like these in microseconds. Unbuffered on a PC, every call waits for the drive. On a SATA SSD each one took about 1 ms, so the loading screen ran for 70-76 s. During that time the drive read only about 5 MB/s at 99% busy, and the CPU was idle.

With this change, a read-only open (no write access asked for) goes to the host without FILE_FLAG_NO_BUFFERING and FILE_FLAG_RANDOM_ACCESS. The host's file cache and read-ahead then serve the reads. The bytes the title gets are the same, since an unbuffered handle only adds alignment rules. Opens for writing keep their flags.

  • On by default.
  • VICTORY_FILE_BUFFERED=0 goes back to the title's own flags.
  • The change is limited to crates/victory-hle/src/modules/files.rs: 154 lines added, none removed.
  • It includes a unit test for the flag rule.

How it was found

Windows performance counters were recorded during loading (typeperf).

  • During the loading screen: E: was 98-99% busy, reading 3-16 MB/s. That was 700-1,100 reads a second at 0.9-1.6 ms each, with the CPU at 2-6%.
  • Which process read: victory did all the reading. Microsoft Defender read 0 bytes, and an exclusion made no difference.
  • Not DirectStorage: with VICTORY_DSTORAGE_LOG, DirectStorage made only 51 requests in that window. Its burst right after (90k requests, 2.5 GB) was fast.
  • The cause: the title's own synchronous ReadFile calls. A log of the flags on each open showed the NO_BUFFERING handles.

Results

RTX 5070 Ti 16 GB, Ryzen 7 7800X3D, 32 GB. Game on a SATA SSD. Windows 11, Series X profile, 1440p, DLSS Quality, release build.

Metric: time from the start of the log to the first frame of the world (over 1,000 draws).

Runs Start to world
Before 3 129 / 139 / 133 s
After 2 47 / 48 s
After, first start after a PC restart (cold cache) 1 58 s
  • Loading burst after the change: 82,432 ReadFile calls in 3.5-5.5 s, at 4 µs each. On a cold start there is one extra burst of 23,079 calls at 18 µs each.
  • Frame times in the world: unchanged. Same benchmark route, draw-count corrected: +0.5 ms, within noise.
  • Textures: no more texture re-upload warnings than before (82 vs 97). No new errors and no crashes.

Who gains

The gain scales with how long the drive takes to answer one small read, multiplied by the ~80,000 reads:

  • HDD: the most.
  • SATA SSD: tens of seconds. This drive was slow at about 1 ms per read, so typical SATA drives will gain less.
  • NVMe: a few seconds.
  • Any drive, on later starts: the cached data is served from RAM.

An HDD before/after is planned and will be added here.

Log

  • The first open of each kind of flags is logged with its path.
  • Loading bursts (1,000 or more ReadFile calls in 2 s) get a summary line: calls, how many were 4 KiB or less, MB, and µs per call. Outside loading the log stays quiet.

🤖 Generated with Claude Code

**@⁠aidanthehorrible** on GitHub · 2026-11-28 09:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/941) `aidanthehorrible:pr/file-buffered` → `main` · +161 −0 · 1 files · 2 commits · merged 2026-11-29 08:16 UTC ## What The title opens each of its archives twice. The second open uses `FILE_FLAG_NO_BUFFERING` (63 of the 127 opens in a run). At loading it then reads them in about 80,000 small synchronous `ReadFile` calls, one at a time. Most calls are 4 KiB or less. The console's storage serves reads like these in microseconds. Unbuffered on a PC, every call waits for the drive. On a SATA SSD each one took about 1 ms, so the loading screen ran for 70-76 s. During that time the drive read only about 5 MB/s at 99% busy, and the CPU was idle. With this change, a read-only open (no write access asked for) goes to the host without `FILE_FLAG_NO_BUFFERING` and `FILE_FLAG_RANDOM_ACCESS`. The host's file cache and read-ahead then serve the reads. The bytes the title gets are the same, since an unbuffered handle only adds alignment rules. Opens for writing keep their flags. - On by default. - `VICTORY_FILE_BUFFERED=0` goes back to the title's own flags. - The change is limited to `crates/victory-hle/src/modules/files.rs`: 154 lines added, none removed. - It includes a unit test for the flag rule. ## How it was found Windows performance counters were recorded during loading (`typeperf`). - **During the loading screen:** E: was 98-99% busy, reading 3-16 MB/s. That was 700-1,100 reads a second at 0.9-1.6 ms each, with the CPU at 2-6%. - **Which process read:** `victory` did all the reading. Microsoft Defender read 0 bytes, and an exclusion made no difference. - **Not DirectStorage:** with `VICTORY_DSTORAGE_LOG`, DirectStorage made only 51 requests in that window. Its burst right after (90k requests, 2.5 GB) was fast. - **The cause:** the title's own synchronous `ReadFile` calls. A log of the flags on each open showed the `NO_BUFFERING` handles. ## Results RTX 5070 Ti 16 GB, Ryzen 7 7800X3D, 32 GB. Game on a SATA SSD. Windows 11, Series X profile, 1440p, DLSS Quality, release build. Metric: time from the start of the log to the first frame of the world (over 1,000 draws). | | Runs | Start to world | |---|---|---| | Before | 3 | 129 / 139 / 133 s | | After | 2 | 47 / 48 s | | After, first start after a PC restart (cold cache) | 1 | 58 s | - **Loading burst after the change:** 82,432 `ReadFile` calls in 3.5-5.5 s, at 4 µs each. On a cold start there is one extra burst of 23,079 calls at 18 µs each. - **Frame times in the world:** unchanged. Same benchmark route, draw-count corrected: +0.5 ms, within noise. - **Textures:** no more texture re-upload warnings than before (82 vs 97). No new errors and no crashes. ## Who gains The gain scales with how long the drive takes to answer one small read, multiplied by the ~80,000 reads: - **HDD:** the most. - **SATA SSD:** tens of seconds. This drive was slow at about 1 ms per read, so typical SATA drives will gain less. - **NVMe:** a few seconds. - **Any drive, on later starts:** the cached data is served from RAM. An HDD before/after is planned and will be added here. ## Log - The first open of each kind of flags is logged with its path. - Loading bursts (1,000 or more `ReadFile` calls in 2 s) get a summary line: calls, how many were 4 KiB or less, MB, and µs per call. Outside loading the log stays quiet. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
- The game opens each of its archives twice, once with
  FILE_FLAG_NO_BUFFERING (63 of 127 opens), and at loading reads them in
  some 80,000 small synchronous ReadFile calls (most 4 KiB or less), one at
  a time. On a SATA SSD each unbuffered call took about 1 ms: the loading
  screen read ~5 MB/s for 70-76 s, the drive 99% busy, the CPU idle.
  DirectStorage made only 51 requests in that stretch.
- A read-only open (no write access asked for) now goes to the host
  without FILE_FLAG_NO_BUFFERING and FILE_FLAG_RANDOM_ACCESS, so the host's
  file cache and read-ahead serve it: the same calls took 4 us each. From
  the start to the first frame of the world (over 1,000 draws): 129-139 s
  before (3 runs), 47-48 s after (2 runs), 58 s on the first start after a
  restart (RTX 5070 Ti, Ryzen 7 7800X3D, 32 GB, game on a SATA SSD, Series
  X, release build). Frame times in the world unchanged. The bytes read are
  the same; opens for writing keep their flags. VICTORY_FILE_BUFFERED=0
  goes back to the game's flags.
- The gain scales with the drive's latency for one small read: an HDD
  should gain the most, an NVMe drive a few seconds; later starts gain on
  any drive, from the cache.
- The log names the first open of each kind of flags with its path, and
  sums up the game's ReadFile calls in loading bursts (1,000 or more in
  2 s): calls, how many of 4 KiB or less, MB, microseconds a call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
As in Marvisak/VIctory#2427: an overlapped open keeps
FILE_FLAG_NO_BUFFERING, since the host's ReadFileScatter takes only a
handle with both. In our runs the game opened its archives synchronous
only (flags 0x20000000), so the measured results are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 14:30:40 +00:00
Author
Owner

@⁠aidanthehorrible on GitHub · 2026-11-28 09:40 UTC · original

Credit where it's due: after posting I found that @⁠imjustprism made the same core change in Marvisak/VIctory#2427 (Nov 25, still open there), with HDD numbers: 49 s -> 21 s cold, about 7x on later starts. We found the cause independently through our own measurements, and this PR brings it to VIctory-NVIDIA with SATA SSD numbers.

Following #2427, the second commit keeps the flags of overlapped opens (ReadFileScatter needs no buffering). The title only opened its packs synchronously in our runs, so the results above stand.

**@⁠aidanthehorrible** on GitHub · 2026-11-28 09:40 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/941#issuecomment-7237397315) Credit where it's due: after posting I found that @⁠imjustprism made the same core change in Marvisak/VIctory#2427 (Nov 25, still open there), with HDD numbers: 49 s -> 21 s cold, about 7x on later starts. We found the cause independently through our own measurements, and this PR brings it to VIctory-NVIDIA with SATA SSD numbers. Following #2427, the second commit keeps the flags of overlapped opens (ReadFileScatter needs no buffering). The title only opened its packs synchronously in our runs, so the results above stand.
Author
Owner

@⁠ArturoWolff on GitHub · 2026-11-28 10:16 UTC · original

Independent Proton/NVMe data point for aidanthehorrible's PR and imjustprism's earlier #2427. Tested head 1f3f24a1da51bb904b9d372c31f882781e765fe5 (the current rewritten head 082c5c3679b01c561698eb62e76bdec97a36da9e has the identical Git tree 0f26ea75597bfb68aec295fda7c4c8e1d40a274a). Applied only its files.rs delta onto our already-tested #925 helper compiler + Linux backing baseline. RTX 4060 8 GB / 16 GB RAM, NVIDIA 620.73.04, GE-Proton11-14, Series X 1080to1440, DLSS/FG off, normal waits and full requested effects/write-back. Same release executable, cloned profile, fresh external caches, off then on; host page cache not forcibly cleared.

Reported ReadFile observations VICTORY_FILE_BUFFERED=0 =1
Read-only NO_BUFFERING open, flags sent 0x20000000 0x00000000
Observed read/write open, flags sent 0x80 0x80
Calls across three logged windows 105738 105977
Calls <=4 KiB 86309 86323
Requested MB 713.4 642.9
Approx. count-weighted mean host-call time (us) 20.08 4.36
Largest burst calls / reported mean us 82188 / 17 82429 / 3
Whole guarded launch duration (s) 127.483 137.062
Minimum available host RAM (MiB) 1460.5 1940.5
Actual exit 5 5

The receiving path is exercised: the policy changes the expected read-only open flags, and the observed read/write flags stay the same. The host call timing is lower in the buffered arm, but requested bytes are not matched, the cache state is uncontrolled at host level, and these are rounded logged windows rather than complete read traces (requested lengths, not completed bytes). This pair does not establish a causal speedup magnitude, byte equivalence, all overlapped/write semantics, or total loading improvement. Both actual runs still end at the existing #628 loading failure (black overlay, no playable world); no memory guard stop, OOM, GPU fault or reported device/fence/host upload refusal. The unbuffered baseline already reports microsecond-scale host calls here rather than SATA's millisecond-scale calls, so this looks less promising as the immediate local world-entry fix. No game data or raw logs attached.

AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).

**@⁠ArturoWolff** on GitHub · 2026-11-28 10:16 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/941#issuecomment-7237788667) Independent Proton/NVMe data point for aidanthehorrible's PR and imjustprism's earlier #2427. Tested head `1f3f24a1da51bb904b9d372c31f882781e765fe5` (the current rewritten head `082c5c3679b01c561698eb62e76bdec97a36da9e` has the identical Git tree `0f26ea75597bfb68aec295fda7c4c8e1d40a274a`). Applied only its `files.rs` delta onto our already-tested #925 helper compiler + Linux backing baseline. RTX 4060 8 GB / 16 GB RAM, NVIDIA 620.73.04, GE-Proton11-14, Series X 1080to1440, DLSS/FG off, normal waits and full requested effects/write-back. Same release executable, cloned profile, fresh external caches, off then on; host page cache not forcibly cleared. | Reported ReadFile observations | `VICTORY_FILE_BUFFERED=0` | `=1` | |---|---:|---:| | Read-only `NO_BUFFERING` open, flags sent | `0x20000000` | `0x00000000` | | Observed read/write open, flags sent | `0x80` | `0x80` | | Calls across three logged windows | 105738 | 105977 | | Calls <=4 KiB | 86309 | 86323 | | Requested MB | 713.4 | 642.9 | | Approx. count-weighted mean host-call time (us) | 20.08 | 4.36 | | Largest burst calls / reported mean us | 82188 / 17 | 82429 / 3 | | Whole guarded launch duration (s) | 127.483 | 137.062 | | Minimum available host RAM (MiB) | 1460.5 | 1940.5 | | Actual exit | 5 | 5 | The receiving path is exercised: the policy changes the expected read-only open flags, and the observed read/write flags stay the same. The host call timing is lower in the buffered arm, but requested bytes are not matched, the cache state is uncontrolled at host level, and these are rounded logged windows rather than complete read traces (requested lengths, not completed bytes). This pair does not establish a causal speedup magnitude, byte equivalence, all overlapped/write semantics, or total loading improvement. Both actual runs still end at the existing #628 loading failure (black overlay, no playable world); no memory guard stop, OOM, GPU fault or reported device/fence/host upload refusal. The unbuffered baseline already reports microsecond-scale host calls here rather than SATA's millisecond-scale calls, so this looks less promising as the immediate local world-entry fix. No game data or raw logs attached. AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).
Author
Owner

@⁠aidanthehorrible on GitHub · 2026-11-28 17:20 UTC · original

HDD test, as promised. Same PC, game copied to an HDD, cold start after a restart each time:

Fix off Fix on
Start to first scene 167 s 120 s
Read from the drive 2.7 GB 1.9 GB

About 47 s faster on a cold HDD start. Smaller in proportion than on my SATA SSD, because most of the HDD's loading time goes to scattered reads that this change doesn't touch.

**@⁠aidanthehorrible** on GitHub · 2026-11-28 17:20 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/941#issuecomment-7242934523) HDD test, as promised. Same PC, game copied to an HDD, cold start after a restart each time: | | Fix off | Fix on | |---|---|---| | Start to first scene | 167 s | 120 s | | Read from the drive | 2.7 GB | 1.9 GB | About 47 s faster on a cold HDD start. Smaller in proportion than on my SATA SSD, because most of the HDD's loading time goes to scattered reads that this change doesn't touch.
github manually merged commit 6c062cb48b into main 2026-11-29 08:22:16 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!941
No description provided.