Feature: cache the checksums of files that Igir writes - #2427
Open
sdornan wants to merge 1 commit into
Open
Conversation
The file cache is keyed by absolute file path, so a ROM that Igir copies or moves to a new location has no cached result at its new path, and has to be read again in full on the next run. This is the expensive part of scanning, and it's entirely avoidable: Igir already knows the checksums of every file it writes. Cache what we already know at the output path after a successful write: - Raw copies and moves write the input file's bytes unchanged, so the input file's checksums are also the output file's checksums. - Zip writing knows the checksums of every entry it wrote, so cache them as the output zip's archive entries. Results aren't cached for writes that change the file's contents, since the input file's checksums no longer describe the output file. That covers header removal, patching, and restoring padding to trimmed ROMs. Checksums also aren't cached when the file on disk isn't the size we expected to write. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FjyVaGcxiAUaAfjxGH2cqg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The file cache is keyed by absolute file path (
FileCache#getCacheKey), so a ROM that Igir copies or moves to a new location has no cached result at its new path and has to be read again in full on the next run. Nothing in the write path ever touched the cache.This is avoidable: Igir already knows the checksums of every file it writes, and currently throws that knowledge away.
ROM headers, file signatures, and paddings already survive a move, since they're keyed by checksum rather than path. Only plain-file checksums and archive entry checksums are path-keyed — and those are the expensive ones.
Changes
After a successful write, cache what we already know at the output path:
copy --zip/move --zipwould still pay a full decompress on the next run.New
FileCache#setFileChecksumsandFileCache#setArchiveChecksums, exposed throughFileFactory, called fromCandidateWriterafterwriteRawSingleandwriteZipsucceed.Safety
CandidateWriter.isTransformedWhenWritten.movemode, andteststill verifies before anything is trusted. This is called out in the docs rather than left implicit.Verification
Unit tests for the new cache methods, plus writer-level tests covering copy and move for both raw and zip output, and the header-removal negative case.
End-to-end against the repo's fixtures with a real cache file, using
dir2datto force a full scan-and-hash of the output directory:The cache file is byte-identical before and after the rescan, so nothing was recomputed. Same result for the
--zippath.Control run with the source changes stashed: the copy produced 0 output-path cache keys and the following rescan had to compute all 11, confirming the difference is real.
Not included
Re-keying an existing archive's cached entry list when a whole
.zipis moved as-is (anArchiveFileinput). That's a different mechanism from the seed-on-write approach here, and a narrower case — happy to follow up separately.Pull request checklist
npm testhas been run locally for your change (91 files, 3269 tests passing, lint clean)docs/advanced/file-cache.md)c5d485e, please confirm this is current with upstreammain