fix: lru local cache eviction #71 - #1481
Open
asmyshlyaev177 wants to merge 1 commit into
Open
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
Limit local cache size with per-script LRU eviction
Fixes #71
Problem
.wireit/<script>/cache/<fingerprint>/gains a full copy of the script'soutputper fingerprint, and nothing removes them. The README told users torm -rf .wireit/*/cacheby hand.Cheap when
outputisdist/, expensive when it isn't. A repo declaringnode_modulesas output reached 73 GB at ~540 MB per entry.Change
LocalCachekeeps the N most recently used entries per script — written byset()or read byget(). Eviction runs after each successfulset().WIREIT_CACHE_MAX_ENTRIESoverrides: positive integer, orinfinityfor the old behavior. Parsed like the existingWIREIT_PARALLEL.output, so N multipliesa script's disk usage, and large-output scripts are the painful case. 2 covers
bouncing between the current state and one other (a branch, an undo).
Recency = directory mtime
No index file, no consistency problem.
get()stamps the entry it returns, so afrequently restored entry isn't evicted for being old — that's LRU rather than
FIFO.
atimeis unusable: filesystems are commonly mountednoatimeorrelatime.Locking
None added. Eviction touches only the calling script's own cache folder, and
StandardScriptExecution#acquireSystemLockIfNeededalready holds that script'slock across
get()andset(). It skips the lock only for an emptyoutput,where entries are empty directories.
Housekeeping never fails a script
Stamping and eviction swallow errors:
Degraded behavior is "cache larger than requested", not a failed build.
Entries are ranked with
lstat, notstat, so a broken symlink in the folder isevicted instead of throwing on every future eviction.
Tests
src/test/local-cache.test.ts, unit-testingLocalCachewith explicit mtimes soordering doesn't depend on timestamp resolution:
get()on older entryinfinityget()returnsundefinedPlus an end-to-end CLI test — 5 runs under
WIREIT_CACHE_MAX_ENTRIES=2, 2entries left — and a
cli-optionsparse test. All run undernpm run test:cache-local.Compatibility
Previously unbounded caches are now trimmed; set
WIREIT_CACHE_MAX_ENTRIES=infinityto opt out. Existing over-limit folders trimon that script's next cache write.