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

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

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


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

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

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

Review: COMMENTED


Reviewed head 3efb59f. cargo test -p xcl --lib vfs → 24 passed, 0 failed here. Paired smoke blocks are present. The overlay_used gating looks sound: the writers set the flag before creating anything in the overlay, and the earlier-run/whiteout-only cases have tests.

Question: the PR's 60 s smoke block reports 1223 frames against main's 1434 (about 15% fewer), although both end at 60 presents per 2 s. For a change meant to cut per-open cost, is that difference expected run-to-run noise? Otherwise no issue found.

AI-assisted (OpenCode).

<!-- greyfinch-sync:ivall/xcl:review:6040665455 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1106#pullrequestreview-6040665455). Originally posted by [sds-228](https://github.com/sds-228) on 2026-11-24T14:06:27Z. **Review:** COMMENTED --- Reviewed head `3efb59f`. `cargo test -p xcl --lib vfs` → 24 passed, 0 failed here. Paired smoke blocks are present. The `overlay_used` gating looks sound: the writers set the flag before creating anything in the overlay, and the earlier-run/whiteout-only cases have tests. Question: the PR's 60 s smoke block reports 1223 frames against main's 1434 (about 15% fewer), although both end at 60 presents per 2 s. For a change meant to cut per-open cost, is that difference expected run-to-run noise? Otherwise no issue found. AI-assisted (OpenCode).
DavidM1911 commented 2026-11-25 09:08:13 +00:00 (Migrated from github.com)

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


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:7156932767 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1106#issuecomment-7156932767). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T08:21:49Z. --- 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:10 +00:00 (Migrated from github.com)

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


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:7262316708 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1106#issuecomment-7262316708). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T20:44:10Z. --- 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:50:05 +00:00 (Migrated from github.com)

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


Triage (#1607) – head 3efb59f

#1092 (same author, same issue #999) also cuts file-system probes from opens, but at a different point: it skips the two visible_in_* probes for plain reads in open_decision. This PR skips the overlay probes in visible_in_overlay, is_dir and needs_merge while the overlay holds nothing. They are complementary and neither contains the other.
All writers I found inside vfs.rs set the flag before creating anything (prepare_write, the copy/move staging, create_dir). The branch conflicts with main's newer vfs.rs changes (MAXIMUM_ALLOWED routing, .. handling). No problems found in the diff.
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:7301148618 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1106#issuecomment-7301148618). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:50:05Z. --- **Triage (#1607)** – head 3efb59f #1092 (same author, same issue #999) also cuts file-system probes from opens, but at a different point: it skips the two `visible_in_*` probes for plain reads in `open_decision`. This PR skips the overlay probes in `visible_in_overlay`, `is_dir` and `needs_merge` while the overlay holds nothing. They are complementary and neither contains the other. All writers I found inside vfs.rs set the flag before creating anything (`prepare_write`, the copy/move staging, `create_dir`). The branch conflicts with main's newer vfs.rs changes (MAXIMUM_ALLOWED routing, `..` handling). No problems found in the diff. 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!1097
No description provided.