Repository navigation
perf: skip re-hashing unchanged watched files on every build check - #625
Merged
ElMassimo merged 2 commits intoSep 16, 2026
Merged
Conversation
With autoBuild on, every asset helper asks the builder whether the build is stale, and each check reads and hashes every watched file. On an app with ~1850 watched files (72 MB) one check costs ~100 ms on a native filesystem and ~460 ms on a bind mount, and the answer is almost always "not stale". The one-second memo decides how often that is paid, and it works against you exactly when things are slow: the slower the render, the more likely the next helper call falls outside the window. Caching each file's id under its mtime and size drops the same check to ~6 ms. The digest stays content-based, so a checkout that changes mtimes but not contents does not trigger a build; files touched within the last second are read again regardless, the way Git resolves a racily clean index entry. Closes ElMassimo#624
Owner
|
Hi Kirill! I like this optimization, it's small and self-contained, so it feels like a reasonable addition. That said, I notice that you mention As mentioned in the guide, it's recommended to set |
Contributor
Author
|
Thanks for merging, and for the pointer on |
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.
Description 📖
This pull request makes the
autoBuildstaleness check stop re-reading watched files that have not changed. Closes #624, where the measurements are written up in full.Background 📜
Every call to a
vite_*helper goes throughManifest#lookup, which callsbuilder.build, which callswatched_files_digest— a glob overconfig.watched_pathsplusDigest::SHA1.fileon every one of them.@last_digest_atmemoizes the result, but only for a second.On an app with ~1850 watched files (72 MB under
app/javascript) one pass costs:Dir[]File.stat× 1846Digest::SHA1.file× 1846The traversal is cheap; reading 72 MB to hash it is the whole cost, and the answer is nearly always "not stale".
The one-second memo decides how often that is paid, and it works against you exactly when things are slow: the slower the render, the more likely the next helper call falls outside the window. Our layout makes five lookups that reach the manifest. Locally they coalesce into one pass; on our CI runner they do not — a captured log shows 540
buildcalls in one run.The Fix 🔨
By keeping each file's id under its
mtimeand size, and reading the file again only once that changes.In one integration-test file (29 tests,
autoBuild: true) the time spent inside the staleness check went from 2052 ms to 232 ms, over the same 64buildcalls.Three things worth calling out:
mtimeplus size can collide only for an edit landing within the clock resolution of an earlier one, andrecently_modified?re-reads exactly those files — the rule Git applies to racily clean index entries.Build#stale?and the contents oflast-build-*.jsonare untouched. The cache lives on theBuilderinstance and is rebuilt on each pass, so deleted files drop out of it on their own.Two tests are added: one asserts that a second pass reads nothing from disk and that touching a file re-reads that file and only that file; the other asserts that changed contents still change the digest.
#624also names a second, smaller cost —Manifest#manifestre-reading and re-parsingmanifest.jsonon every lookup whenauto_buildis on. That one is not in this pull request; happy to send it separately if you want it.