Skip to content

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

Open
DTsordas wants to merge 1 commit into
xcl-dev:mainfrom
DTsordas:vfs-read-open-one-probe
Open

DTsordas wants to merge 1 commit into
xcl-dev:mainfrom
DTsordas:vfs-read-open-one-probe

Conversation

@DTsordas

@DTsordas DTsordas commented Nov 24, 2026 •

Copy link
Copy Markdown

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); Tests: capture the truncate error before checking for Wine #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

… 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>

@sds-228 sds-228 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

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