Skip to content

[upstream #1092] VFS: a plain read of a game file asks the file system once, not three times - #64

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1092
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1092

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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 xcl-dev#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); Tests: capture the truncate error before checking for Wine xcl-dev/xcl#633 fixes that test.

Regression run

Not run yet: there's no runnable title on this machine. A tester with any unpacked Xbox Series title can supply the pair (the title need not reach this code): in clean checkouts of main and of this PR's head, cargo build --release -p xcl then .\scripts\smoke.ps1 -Game '<folder>' -Seconds 60, same title and machine, and post both xcl-smoke blocks here. I'll put them in this section.

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


Mirror of xcl-dev#1092 (auto-synced, do not edit).

… times

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 xcl-dev#999

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1092 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1092 branch November 25, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VFS: a plain read of a game file checks the file system three times before the open (about 4x a native open)

2 participants