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

Closed
DTsordas wants to merge 1 commit from upstream-pr/1092 into main
DTsordas commented 2026-11-24 11:28:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DTsordas on 2026-11-24T11:28:24Z.


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

<!-- greyfinch-sync:ivall/xcl:issue:5471267279 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1092). Originally posted by [DTsordas](https://github.com/DTsordas) on 2026-11-24T11:28:24Z. --- 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)
sds-228 commented 2026-11-24 14:06:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by sds-228 on 2026-11-24T14:06:29Z.

Review: APPROVED


Reviewed head 639397a. cargo test -p xcl --lib vfs → 24 passed, 0 failed here. The plain-read fast path excludes every write-like open: is_write covers write access, CREATE_NEW, CREATE_ALWAYS, TRUNCATE_EXISTING and delete-on-close, with OPEN_ALWAYS checked separately. Paired smoke block shows 1500 frames against main's 1434. No issue found.

AI-assisted (OpenCode).

<!-- greyfinch-sync:ivall/xcl:review:6040665828 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1092#pullrequestreview-6040665828). Originally posted by [sds-228](https://github.com/sds-228) on 2026-11-24T14:06:29Z. **Review:** APPROVED --- Reviewed head `639397a`. `cargo test -p xcl --lib vfs` → 24 passed, 0 failed here. The plain-read fast path excludes every write-like open: `is_write` covers write access, `CREATE_NEW`, `CREATE_ALWAYS`, `TRUNCATE_EXISTING` and delete-on-close, with `OPEN_ALWAYS` checked separately. Paired smoke block shows 1500 frames against main's 1434. No issue found. AI-assisted (OpenCode).
DavidM1911 commented 2026-11-25 09:08:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T08:36:46Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7157253553 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1092#issuecomment-7157253553). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T08:36:46Z. --- 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!
github-actions[bot] commented 2026-11-29 20:44:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T20:44:05Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7262315621 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1092#issuecomment-7262315621). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T20:44:05Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 04:47:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:47:57Z.


Triage (#1607) – head 639397a

#1106 is the other PR for #999. It skips the overlay probes while the overlay is empty; this PR skips the two visibility probes in vfs.rs:open_decision_for on plain reads. They complement each other and do not duplicate. Main still runs visible_in_overlay and visible_in_original before read_path_rel on every read. The PR conflicts with main.
The new test pins behaviour that was already correct, so it passes without the change too. That is expected for a change that only removes file-system calls.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301112183 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1092#issuecomment-7301112183). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:47:57Z. --- **Triage (#1607)** – head 639397a #1106 is the other PR for #999. It skips the overlay probes while the overlay is empty; this PR skips the two visibility probes in vfs.rs:open_decision_for on plain reads. They complement each other and do not duplicate. Main still runs visible_in_overlay and visible_in_original before read_path_rel on every read. The PR conflicts with main. The new test pins behaviour that was already correct, so it passes without the change too. That is expected for a change that only removes file-system calls. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Pull request closed

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
xcl-dev/xcl!1083
No description provided.