Repository navigation
loader: content-address PreparedImage with cached hash and synced staging (D3D12-LOADER-CONTENT-ADDRESSED-IMAGE) - #2890
Conversation
|
Independent prepared-image publication and retry check at 2624397 + 0ff8a53, using the Win64 test binary under Wine 11.22. The 7 prepare tests including my integration case and all 5 publish tests passed. I used the linked test executable as input. Two originals with different checksum bytes converge to identical prepared bytes and the same content-addressed name. Two distinct prepared payloads of exactly the same length instead publish to separate names. Four concurrent writers, two per name, left both payloads byte-for-byte correct and no staging files. I then truncated one published file and held it open without delete sharing. Publishing returned PermissionDenied and left no staging file. Closing the reader and retrying repaired the truncated file while the other cache entry stayed byte-identical. This exercises the recovery path for a size mismatch with live Windows sharing semantics under Wine. Same-length corruption and power-loss durability were outside the fixture. MEASURED with synthetic inputs. AI-assisted (Codex). |
KelboLive
left a comment
There was a problem hiding this comment.
Content-addressing checks out: the key is blake3(prepared bytes) (prepare.rs:112-118, publish.rs:16-18), so it covers the original image plus any change in prepare(), and the LEONIDA_* options only patch mapped memory after LoadLibraryExW (windows.rs:90-110) — correctly not part of the file key. The old 16-hex collision is gone, and I confirmed the mutation that shrinks the key to 16 hex fails file_name_uses_full_blake3_of_prepared_bytes. 86/86 lib tests here, and the three-way merge with #2889/#2891 compiles and passes 89/89.
Two things to tighten:
- The fast path trusts (name, size) alone (
publish.rs:30-34), so a same-length corruption — bit rot, AV rewrite, interrupted copy, a hand-placed file — is served forever and never healed, unlike the previous byte-compare. Your own test encodes that deliberately (publish.rs:93-98). That is a reasonable trade for the scale win, but it should be stated in the doc comment, or a smallhash.oksidecar written after the rename would restore self-repair. - The safety argument rests on
sync_allbefore rename (publish.rs:59), and deleting that line leaves all 86 tests green. A test hook that asserts the flush happens would pin the one invariant the whole design leans on.
Nit: a crash mid-write leaves .<64hex>.dll.<pid>.<n>.tmp (up to ~200 MB) unreaped — no startup sweep, no age-based reaping. Pre-existing pattern, but this is the cache-hygiene PR, so a stale .*.tmp sweep would close the staging lifecycle.
Merge is clean against current main (the three touched files are byte-identical upstream), and clean paired with #2889 and #2891. CI's red check/linux-python-and-viewer are untouched Python tool tests, not this diff.
|
Verified on native Windows 11 (MSVC target, rustc 1.98.1, NTFS), since the runs in the description are under Wine. Head
Both new tests catch their change:
What the fast path saves here. I timed the two paths on a 114.7 MB file (the size
So with a warm cache the launch saves about 15-20 ms net, since the new hash costs about half of what the skipped read-back cost. With a cold cache the read-back costs more, so the saving should be larger. I did not measure that. Two notes, neither blocking:
Not checked: the game, and a cold-cache launch. GPUs tested: n/a (CPU and file system tests only). AI-assisted: yes (Claude Code). |
Claimed in the coordination issue as:
D3D12-LOADER-CONTENT-ADDRESSED-IMAGE.What and why
Content-address
PreparedImage::file_name()by a cached full BLAKE3 hash of the prepared bytes, sync staging files to disk before the atomic rename, and add a content-addressed fast path inpublish::write_content_addressed()(d3d12/crates/leonida-loader/src/{prepare.rs,publish.rs,windows.rs}).main,PreparedImage::file_name()keys the cached DLL on the first 16 hex chars oforiginal_hash(leonida-image-<16hex>.dll). If loader preparation bytes change for the same title build, the cached filename collides with the stale DLL.publish::write_if_changed()reads the entire ~115–200 MB prepared DLL back from disk into aVec<u8>just to byte-compare it againstprepared.bytes.prepare.rs: computes and cachespub prepared_hash: blake3::Hashonce insideprepare().PreparedImage::file_name(&self)delegates tocrate::publish::content_addressed_name(&self.prepared_hash)(leonida-image-<64hex>.dll), so neitherwindows.rs::loadnorapps/leonida/src/run.rsre-hashesprepared.bytes.publish.rs:write_staging()(File::create→write_all→sync_all, cleaning up the staging file on error) BEFOREpublish_staging()performs the atomic rename, preventing crash/power-loss from leaving a same-size zero-filled file at the content-addressed path.write_content_addressed(path, bytes, hash)which skips re-reading disk when the filename matchescontent_addressed_name(hash)andmetadata(path)confirms a regular file of the exact byte length, falling back towrite_if_changed()otherwise.windows.rs: passes&prepared.prepared_hashintocrate::publish::write_content_addressed, ensuringprepared.bytesis hashed exactly once per launch.LEONIDA_WRITE_SITEScaches keyed by the old 16-heximage_namewill regenerate once under the new 64-hex name; priorleonida-image-*.dllcache entries from earlier builds remain untouched in the cache directory.VirtualProtectbatching is split into its own separate PR (D3D12-LOADER-BATCHED-IAT-PROTECT, verified clean merge viagit merge-tree).prepare.rs,publish.rs,windows.rs) + fresh red→green unit tests + MEASURED 300 s in-world game gate.Tested
python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-loader/src/prepare.rs d3d12/crates/leonida-loader/src/publish.rs d3d12/crates/leonida-loader/src/windows.rs→ exit 0.cargo clean -p leonida-loader --target x86_64-pc-windows-msvc)leonida-loaderunit test binary (x86_64-pc-windows-msvc) and ran under Wine:origin/main(only the new testprepare::tests::file_name_uses_full_blake3_of_prepared_bytesapplied):262439781(rebased onto3e7b34a52):git merge-tree --write-tree HEAD pr/loader-batched-iat-protect→ clean merge (zero conflicts withD3D12-LOADER-BATCHED-IAT-PROTECT).262439781, Series S + DLSS Quality1280×720 → 1920×1080, Option Amods/gate_drivermode = roamloaded):310.03 sin-world after world entry at68.77 s; also passed an earlier cold-cache 310.18 s run with0errors).3,275frames after +60 s (3,382total world presents),15.98median FPS (16.37end median FPS),111.22 msp95 frame time,4.433 slongest present gap (<= 10.0 s).6,686 MiBpeak VRAM (<= 7,400 MiB),0device losses (0x887A0005),0crashes,0panics,0faults before stop,0kernelNVRM: Xiderrors.gate_drivernote:mods/gate_driverloaded inmode = roamwith0GATE FAIL; its 10 s menu-press cadence missed the brief world-entry probe window so the 310.03 s run stayed on the in-world camera cleanly at15.98FPS.GPUs tested: NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Arch Linux (Wine 11.22 + VKD3D-Proton 3.2.0).
AI-assisted: yes (authored by Gemini 4 Neon; independent fresh review pass by a separate Gemini 4 Neon agent requested
File::sync_all()before rename and cachingprepared_hashonce onPreparedImageto eliminate triple hashing, addressed and approved in re-review).Checklist
main(3e7b34a52) and merges cleanly (a conflicting pull request is labeledneeds rebase).check_no_game_data.pyclean on both source and PR description).docs/design.md, with how it was confirmed. (n/a — loader image cache naming & synced content-addressed publish fast path)