VFS: a plain read of a game file asks the file system once, not three times #1092

Open
github-bot wants to merge 1 commit from github-bot/gh-1092 into main AGit
Owner

@⁠DTsordas on GitHub · 2026-11-24 11:28 UTC · original
DTsordas:vfs-read-open-one-probe → main · +31 −0 · 1 files · 1 commits · open

Every CreateFileW / CreateFileA / CreateFile2 of a game file goes through Vfs::open_decision. For a read, open_decision_for called visible_in_overlay and visible_in_original to work out whether the open writes, then read_path_rel called visible_in_overlay again. A plain read (no write access, not OPEN_ALWAYS) never uses the first two answers: the decision is always read_path_rel's. Each check is a std::fs::metadata, which costs about as much as the title's open itself. Now a plain read goes straight to read_path_rel. OPEN_ALWAYS, TRUNCATE_EXISTING, delete-on-close and any write access take the unchanged path. Fixes #999.

Measured with a scratch benchmark (not part of the PR): 200 game files under a G: mount, release build, median of 15 rounds of 200 opens. Main and this PR were run back to back three times, and the table gives the median of the three runs.

per read open (GENERIC_READ, OPEN_EXISTING) main 47efa2e this PR
open_decision 90.5 µs (85.6 / 90.5 / 98.2) 30.0 µs (27.3 / 30.0 / 31.5)
open_decision + File::open of its path 123.8 µs 73.1 µs
bare File::open (reference) 32.4 µs 37.0 µs

The remaining check is the overlay copy, which costs almost as much on a path that doesn't exist. Skipping it while the overlay is empty is its own PR.

What is in it

  • crates/xcl/src/vfs.rs: the early return for a plain read in open_decision_for, and reads_take_the_original_and_read_only_open_always_still_creates, which pins the edge of the fast path: a read-only OPEN_ALWAYS of a missing file still creates it in the overlay. The existing reads_never_touch_and_writes_copy_on_write, delete_is_a_persistent_whiteout and truncate_existing_validation_errors cover the read and validation decisions and pass unchanged.

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Ryzen 5 5600X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug; DXC 1.9.2602.17 (SDK 10.0.26100.0).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 at 639397a (on main 47efa2e), two runs:
    • Run 1: 741 passed, 1 failed, 41 ignored. The test title in e2e lost its GPU at "coherent window headroom" ("GPU fence 1 not reached", then 0x887A0005 for the GPU checks after it). No file check failed.
    • Run 2: 742 passed, 0 failed, 41 ignored, 0 SKIPPED. cargo test -p xcl --test e2e alone, three times: 3 passed each time.
  • cargo test -p xcl --lib vfs: all VFS tests pass except truncate_existing_validation_errors, which fails when it's the first test to call under_wine() (127 instead of 5, on main too); #633 fixes that test.

Regression run

The title's 60 s smoke run (scripts/smoke.ps1, release builds, same machine, back to back with a warm shader cache).

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 9060 XT
title: Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1434 (PresentX 1435)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14905 MB

PR:

xcl-smoke v1
commit: 639397aecdf09776d76e647a274fae42c7282ff9
gpu: AMD Radeon RX 9060 XT
title: Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1500 (PresentX 1501)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14849 MB

Not tested

  • A title's load time: the gain per open is measured, not a whole loading screen.
  • Under Wine; NVIDIA / Intel (no GPU code involved).

AI use

  • Claude Code (Claude Opus 5.5): found the redundant checks, wrote the change, the test, the benchmark and this description. I read the diff and ran the tests and the benchmark above.

🤖 Generated with Claude Code

**@⁠DTsordas** on GitHub · 2026-11-24 11:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/1092) `DTsordas:vfs-read-open-one-probe` → `main` · +31 −0 · 1 files · 1 commits · open Every `CreateFileW` / `CreateFileA` / `CreateFile2` of a game file goes through `Vfs::open_decision`. For a read, `open_decision_for` called `visible_in_overlay` and `visible_in_original` to work out whether the open writes, then `read_path_rel` called `visible_in_overlay` again. A plain read (no write access, not `OPEN_ALWAYS`) never uses the first two answers: the decision is always `read_path_rel`'s. Each check is a `std::fs::metadata`, which costs about as much as the title's open itself. Now a plain read goes straight to `read_path_rel`. `OPEN_ALWAYS`, `TRUNCATE_EXISTING`, delete-on-close and any write access take the unchanged path. Fixes #999. Measured with a scratch benchmark (not part of the PR): 200 game files under a `G:` mount, release build, median of 15 rounds of 200 opens. Main and this PR were run back to back three times, and the table gives the median of the three runs. | per read open (`GENERIC_READ`, `OPEN_EXISTING`) | main `47efa2e` | this PR | |---|---:|---:| | `open_decision` | 90.5 µs (85.6 / 90.5 / 98.2) | 30.0 µs (27.3 / 30.0 / 31.5) | | `open_decision` + `File::open` of its path | 123.8 µs | 73.1 µs | | bare `File::open` (reference) | 32.4 µs | 37.0 µs | The remaining check is the overlay copy, which costs almost as much on a path that doesn't exist. Skipping it while the overlay is empty is its own PR. **What is in it** - `crates/xcl/src/vfs.rs`: the early return for a plain read in `open_decision_for`, and `reads_take_the_original_and_read_only_open_always_still_creates`, which pins the edge of the fast path: a read-only `OPEN_ALWAYS` of a missing file still creates it in the overlay. The existing `reads_never_touch_and_writes_copy_on_write`, `delete_is_a_persistent_whiteout` and `truncate_existing_validation_errors` cover the read and validation decisions and pass unchanged. **Tested** - AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Ryzen 5 5600X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug; DXC 1.9.2602.17 (SDK 10.0.26100.0). - `cargo test --workspace --no-fail-fast -- --test-threads=4` at `639397a` (on main `47efa2e`), two runs: - Run 1: 741 passed, 1 failed, 41 ignored. The test title in `e2e` lost its GPU at "coherent window headroom" ("GPU fence 1 not reached", then 0x887A0005 for the GPU checks after it). No file check failed. - Run 2: 742 passed, 0 failed, 41 ignored, 0 SKIPPED. `cargo test -p xcl --test e2e` alone, three times: 3 passed each time. - `cargo test -p xcl --lib vfs`: all VFS tests pass except `truncate_existing_validation_errors`, which fails when it's the first test to call `under_wine()` (127 instead of 5, on main too); #633 fixes that test. **Regression run** The title's 60 s smoke run (`scripts/smoke.ps1`, release builds, same machine, back to back with a warm shader cache). main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: AMD Radeon RX 9060 XT title: Xbox.v1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1434 (PresentX 1435) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14905 MB ``` PR: ``` xcl-smoke v1 commit: 639397aecdf09776d76e647a274fae42c7282ff9 gpu: AMD Radeon RX 9060 XT title: Xbox.v1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1500 (PresentX 1501) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14849 MB ``` **Not tested** - A title's load time: the gain per open is measured, not a whole loading screen. - Under Wine; NVIDIA / Intel (no GPU code involved). **AI use** - Claude Code (Claude Opus 5.5): found the redundant checks, wrote the change, the test, the benchmark and this description. I read the diff and ran the tests and the benchmark above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
open_decision_for checked the overlay and the original (visible_in_overlay,
visible_in_original) before deciding whether an open writes, then
read_path_rel checked the overlay again. For a read (no write access, not
OPEN_ALWAYS) the first two answers are never used: the decision is the same
read_path_rel. Each check is a std::fs::metadata, which costs about as much
as the title's open itself.

Measured on 200 game files (release, median of 15 rounds, RX 9060 XT box,
Windows 11 26300): open_decision 65 -> 19.5 us, open_decision plus the open
94 -> 50 us, against 23 us for a bare File::open.

Fixes #999

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:43:15 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 08:36 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 08:36 UTC · [original](https://github.com/xcl-dev/xcl/pull/1092#issuecomment-7157253553) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1092/head:github-bot/gh-1092'
git switch 'github-bot/gh-1092'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1092'
git switch 'github-bot/gh-1092'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1092'
git switch 'github-bot/gh-1092'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1092'
git switch 'main'
git merge --squash 'github-bot/gh-1092'
git switch 'main'
git merge --ff-only 'github-bot/gh-1092'
git switch 'main'
git merge 'github-bot/gh-1092'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.