VFS: an empty overlay answers "no copy" without asking the file system #1106

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

@⁠DTsordas on GitHub · 2026-11-24 11:40 UTC · original
DTsordas:vfs-skip-empty-overlay → main · +66 −4 · 1 files · 1 commits · open

Part of #999, and independent of #1092 (either can merge first). Most titles never write their game folder, so the overlay holds nothing, yet every read open of a game file asked the file system whether an overlay copy exists (visible_in_overlay, a std::fs::metadata that costs about as much as the open). So did every directory search in a game folder (is_dir and needs_merge before FindFirstFile).

The VFS now keeps overlay_used. It's set at start when the overlay folder holds anything besides .xcl_whiteouts (an earlier run's copies), and by stage_write, prepare_write and create_dir before they create anything there. Those are the only ways the VFS puts things into the overlay: a move within the overlay needs an existing entry, and ReplaceFileW on game paths goes through the CopyFileW / MoveFileExW hooks. While the flag is clear, visible_in_overlay, is_dir and needs_merge don't ask the file system about the overlay. Something put into the overlay folder by hand during a run is seen from the next run on.

Measured with scratch benchmarks (not part of the PR): 200 game files and 200 game folders under G:, release build, median of 15 rounds of 200, three runs each. The table gives the median of the three runs, with the runs in brackets.

main 47efa2e this PR
open_decision, a read open 95.3 µs (105.8 / 92.9 / 95.3) 46.5 µs (44.0 / 46.5 / 48.0)
open_decision + File::open 138.6 µs 84.6 µs
bare File::open (reference) 35.2 µs 35.5 µs
is_dir + needs_merge before a FindFirstFile 128.0 µs (128.0 / 174.8 / 127.9) 80.0 µs (80.0 / 75.0 / 85.1)
bare read_dir + first entry (reference) 56.5 µs

For the directory rows, the "main" column is an overlay holding an earlier run's copy, which asks the file system as main does. Together with #1092, a read open asks it nothing extra: on an earlier main (077ce40), open_decision went from 65 µs to 2.0 µs with both changes. What's left of the directory checks is is_dir asking the original twice (exists, then is a folder), which is left for its own PR.

What is in it

  • crates/xcl/src/vfs.rs: overlay_used (set in Vfs::new from the overlay folder, and by mark_overlay_used in the three writers), checked first in visible_in_overlay, is_dir and needs_merge.
  • Tests: an_overlay_from_an_earlier_run_is_seen_but_a_whiteout_list_alone_is_none (a new Vfs over an overlay holding only the whiteout list keeps the flag clear and still hides the deleted file; over an earlier run's copy, it reads the copy). Also an_empty_overlay_is_not_asked_until_this_run_writes_to_it: a file and a folder put there behind the VFS's back are not looked for until the VFS writes there. With visible_in_overlay always probing, as on main, the latter fails.
  • remove_dir_checks_both_layers_before_removing_overlay (from 47efa2e) creates its overlay folder directly on disk, so it now marks the overlay used after that, as a run that found the folder at start would. Its assertions are 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 3efb59f (on main 47efa2e): 743 passed, 0 failed, 41 ignored, 0 SKIPPED, including e2e's test_title_runs_and_game_folder_is_untouched.
  • cargo test -p xcl --lib vfs: 24 passed.

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: 3efb59f3a821f727fd5cdc5b1f7ee108095becd6
gpu: AMD Radeon RX 9060 XT
title: Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1223 (PresentX 1224)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15023 MB

Not tested

  • A title's load time: the gain per open is measured, not a whole loading screen.
  • A title that writes its game folder: the flag is set then, and the VFS behaves as on main.
  • Under Wine.

AI use

  • Claude Code (Claude Opus 5.5): wrote the change, the tests, the benchmarks and this description. I read the diff and ran the tests and the benchmarks above.

🤖 Generated with Claude Code

**@⁠DTsordas** on GitHub · 2026-11-24 11:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/1106) `DTsordas:vfs-skip-empty-overlay` → `main` · +66 −4 · 1 files · 1 commits · open Part of #999, and independent of #1092 (either can merge first). Most titles never write their game folder, so the overlay holds nothing, yet every read open of a game file asked the file system whether an overlay copy exists (`visible_in_overlay`, a `std::fs::metadata` that costs about as much as the open). So did every directory search in a game folder (`is_dir` and `needs_merge` before `FindFirstFile`). The VFS now keeps `overlay_used`. It's set at start when the overlay folder holds anything besides `.xcl_whiteouts` (an earlier run's copies), and by `stage_write`, `prepare_write` and `create_dir` before they create anything there. Those are the only ways the VFS puts things into the overlay: a move within the overlay needs an existing entry, and `ReplaceFileW` on game paths goes through the `CopyFileW` / `MoveFileExW` hooks. While the flag is clear, `visible_in_overlay`, `is_dir` and `needs_merge` don't ask the file system about the overlay. Something put into the overlay folder by hand during a run is seen from the next run on. Measured with scratch benchmarks (not part of the PR): 200 game files and 200 game folders under `G:`, release build, median of 15 rounds of 200, three runs each. The table gives the median of the three runs, with the runs in brackets. | | main `47efa2e` | this PR | |---|---:|---:| | `open_decision`, a read open | 95.3 µs (105.8 / 92.9 / 95.3) | 46.5 µs (44.0 / 46.5 / 48.0) | | `open_decision` + `File::open` | 138.6 µs | 84.6 µs | | bare `File::open` (reference) | 35.2 µs | 35.5 µs | | `is_dir` + `needs_merge` before a `FindFirstFile` | 128.0 µs (128.0 / 174.8 / 127.9) | 80.0 µs (80.0 / 75.0 / 85.1) | | bare `read_dir` + first entry (reference) | 56.5 µs | | For the directory rows, the "main" column is an overlay holding an earlier run's copy, which asks the file system as main does. Together with #1092, a read open asks it nothing extra: on an earlier main (`077ce40`), `open_decision` went from 65 µs to 2.0 µs with both changes. What's left of the directory checks is `is_dir` asking the original twice (exists, then is a folder), which is left for its own PR. **What is in it** - `crates/xcl/src/vfs.rs`: `overlay_used` (set in `Vfs::new` from the overlay folder, and by `mark_overlay_used` in the three writers), checked first in `visible_in_overlay`, `is_dir` and `needs_merge`. - Tests: `an_overlay_from_an_earlier_run_is_seen_but_a_whiteout_list_alone_is_none` (a new `Vfs` over an overlay holding only the whiteout list keeps the flag clear and still hides the deleted file; over an earlier run's copy, it reads the copy). Also `an_empty_overlay_is_not_asked_until_this_run_writes_to_it`: a file and a folder put there behind the VFS's back are not looked for until the VFS writes there. With `visible_in_overlay` always probing, as on main, the latter fails. - `remove_dir_checks_both_layers_before_removing_overlay` (from `47efa2e`) creates its overlay folder directly on disk, so it now marks the overlay used after that, as a run that found the folder at start would. Its assertions are 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 `3efb59f` (on main `47efa2e`): 743 passed, 0 failed, 41 ignored, 0 SKIPPED, including `e2e`'s `test_title_runs_and_game_folder_is_untouched`. - `cargo test -p xcl --lib vfs`: 24 passed. **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: 3efb59f3a821f727fd5cdc5b1f7ee108095becd6 gpu: AMD Radeon RX 9060 XT title: Xbox.v1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1223 (PresentX 1224) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15023 MB ``` **Not tested** - A title's load time: the gain per open is measured, not a whole loading screen. - A title that writes its game folder: the flag is set then, and the VFS behaves as on main. - Under Wine. **AI use** - Claude Code (Claude Opus 5.5): wrote the change, the tests, the benchmarks and this description. I read the diff and ran the tests and the benchmarks above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Most titles never write their game folder, so the overlay holds nothing,
yet every read open of a game file asked the file system for an overlay
copy (visible_in_overlay, a std::fs::metadata costing about as much as
the open). The VFS now keeps a flag: set at start when the overlay folder
holds anything besides the whiteout list (an earlier run's copies), and
by stage_write, prepare_write and create_dir before they create anything
there, the only ways the VFS puts things into the overlay. While it is
clear, visible_in_overlay, is_dir and needs_merge answer without asking
the file system about the overlay (needs_merge runs before every
FindFirstFile in a game folder).

Measured on 200 game files (release, median of 15 rounds, three runs):
open_decision 65 -> 33.5 us alone; with the change that skips the unused
checks for plain reads (#999), 65 -> 2.0 us, and a read open costs about
a native open (29-36 us against 25-30 us bare, was 94 us). The checks
before a FindFirstFile in a game folder (is_dir + needs_merge): 114 ->
58 us, against 61 us for the search itself.

Part of #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:38 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 08:21 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:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/1106#issuecomment-7156932767) 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/1106/head:github-bot/gh-1106'
git switch 'github-bot/gh-1106'

Merge

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