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

Open
opened 2026-11-26 04:39:52 +00:00 by github-bot · 1 comment
Owner

@⁠DTsordas on GitHub · 2026-11-24 10:09 UTC · original

Every CreateFileW / CreateFileA / CreateFile2 of a game file goes through Vfs::open_decision. For a read, open_decision_for (crates/xcl/src/vfs.rs:547) calls visible_in_overlay and visible_in_original to work out whether the open writes, then read_path_rel calls 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 of the three checks is a std::fs::metadata, which costs about as much as the title's open itself.

Measured on main 077ce40 (release build, 200 game files under a G: mount, median of 15 rounds of 200 opens, three runs), per read open (GENERIC_READ, OPEN_EXISTING):

main with a plain read going straight to read_path_rel
open_decision 65 µs 19.5 µs
open_decision + File::open of its path 94 µs 50 µs
bare File::open (reference) 23 µs 24 µs

So a title's read open of its own files costs about 4× a native one now, and about 2× with the change.

I have the change with a test that pins the edge of the fast path (a read-only OPEN_ALWAYS of a missing file still creates it in the overlay). The full suite passes with it on an RX 9060 XT (debug, cargo test --workspace -- --test-threads=4: 717 passed, 0 failed, 41 ignored, 0 SKIPPED). I'll open the PR once I have the smoke runs on a title.

AI use: found, measured and written up with Claude Code (Claude Opus 5.5).

**@⁠DTsordas** on GitHub · 2026-11-24 10:09 UTC · [original](https://github.com/xcl-dev/xcl/issues/999) Every `CreateFileW` / `CreateFileA` / `CreateFile2` of a game file goes through `Vfs::open_decision`. For a read, `open_decision_for` (`crates/xcl/src/vfs.rs:547`) calls `visible_in_overlay` and `visible_in_original` to work out whether the open writes, then `read_path_rel` calls `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 of the three checks is a `std::fs::metadata`, which costs about as much as the title's open itself. Measured on main `077ce40` (release build, 200 game files under a `G:` mount, median of 15 rounds of 200 opens, three runs), per read open (`GENERIC_READ`, `OPEN_EXISTING`): | | main | with a plain read going straight to `read_path_rel` | |---|---:|---:| | `open_decision` | 65 µs | 19.5 µs | | `open_decision` + `File::open` of its path | 94 µs | 50 µs | | bare `File::open` (reference) | 23 µs | 24 µs | So a title's read open of its own files costs about 4× a native one now, and about 2× with the change. I have the change with a test that pins the edge of the fast path (a read-only `OPEN_ALWAYS` of a missing file still creates it in the overlay). The full suite passes with it on an RX 9060 XT (debug, `cargo test --workspace -- --test-threads=4`: 717 passed, 0 failed, 41 ignored, 0 SKIPPED). I'll open the PR once I have the smoke runs on a title. **AI use:** found, measured and written up with Claude Code (Claude Opus 5.5).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:39:52 +00:00
Author
Owner

@⁠DTsordas on GitHub · 2026-11-24 10:24 UTC · original

Follow-up measurement: the remaining check can go too. Most titles never write their game folder, so the overlay holds nothing. With a flag, visible_in_overlay answers without a file system call while the overlay is empty. The flag is set at start when the overlay folder holds anything besides .xcl_whiteouts, and by stage_write / prepare_write / create_dir before they create anything.

Same benchmark (200 game files under G:, release, median of 15 rounds of 200 opens, three runs each), per read open:

main 077ce40 plain reads skip the unused checks empty-overlay flag both
open_decision 65 µs 19.5 µs 33.5 µs 2.0 µs
open_decision + File::open 94 µs 50 µs 62 µs 29–36 µs
bare File::open (reference) 23 µs 24 µs 25.5 µs 25–30 µs

With both, a title's read open of a game file costs about as much as a native one. They're two independent changes, so either can merge first, and each has its own tests. The full suite passes with each on an RX 9060 XT (debug, cargo test --workspace --no-fail-fast -- --test-threads=4: 717 / 0 / 41 and 718 / 0 / 41, 0 SKIPPED). I'll open both PRs once I have the smoke runs on a title.

AI use: Claude Code (Claude Opus 5.5) wrote the changes, ran the benchmark and the tests, and wrote this comment.

**@⁠DTsordas** on GitHub · 2026-11-24 10:24 UTC · [original](https://github.com/xcl-dev/xcl/issues/999#issuecomment-7128738249) Follow-up measurement: the remaining check can go too. Most titles never write their game folder, so the overlay holds nothing. With a flag, `visible_in_overlay` answers without a file system call while the overlay is empty. The flag is set at start when the overlay folder holds anything besides `.xcl_whiteouts`, and by `stage_write` / `prepare_write` / `create_dir` before they create anything. Same benchmark (200 game files under `G:`, release, median of 15 rounds of 200 opens, three runs each), per read open: | | main `077ce40` | plain reads skip the unused checks | empty-overlay flag | both | |---|---:|---:|---:|---:| | `open_decision` | 65 µs | 19.5 µs | 33.5 µs | 2.0 µs | | `open_decision` + `File::open` | 94 µs | 50 µs | 62 µs | 29–36 µs | | bare `File::open` (reference) | 23 µs | 24 µs | 25.5 µs | 25–30 µs | With both, a title's read open of a game file costs about as much as a native one. They're two independent changes, so either can merge first, and each has its own tests. The full suite passes with each on an RX 9060 XT (debug, `cargo test --workspace --no-fail-fast -- --test-threads=4`: 717 / 0 / 41 and 718 / 0 / 41, 0 SKIPPED). I'll open both PRs once I have the smoke runs on a title. **AI use:** Claude Code (Claude Opus 5.5) wrote the changes, ran the benchmark and the tests, and wrote this comment.
This discussion has been locked. Commenting is limited to contributors.
No description provided.