Skip to content

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

Open
DTsordas wants to merge 1 commit into
xcl-dev:mainfrom
DTsordas:vfs-skip-empty-overlay
Open

DTsordas wants to merge 1 commit into
xcl-dev:mainfrom
DTsordas:vfs-skip-empty-overlay

Conversation

@DTsordas

@DTsordas DTsordas commented Nov 24, 2026 •

Copy link
Copy Markdown

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

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 (xcl-dev#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 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 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).

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.

2 participants