perf(build): skip redundant cache copy when dist is already fresh#5409
Merged
Conversation
On every `yarn build`, the orchestrator restored each cache-hit package by copying its cached output into `dist` — even when `dist` already held the identical bytes from a previous build. For the full package set this is ~13s of pure syscall-bound file copying on every build, dominating the local edit->rebuild loop. Stamp each package's `dist` with the source hash it was built from (`.webiny-build-hash`). On a cache hit, skip the copy when the marker already matches the current source hash; still copy (and re-stamp) when `dist` is missing or stale. A no-op full build drops from ~15s to ~2s. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 15, 2026
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
Every
yarn buildrestores each cache-hit package byfs.copySync-ing its cached output intodist— even whendistalready contains the identical bytes from the previous build. Across the full package set that's ~13s of pure syscall-bound copying on every build, dominating the local edit→rebuild loop.It's paid whenever most packages are cache hits — i.e. the common case: change one file, rebuild, and it re-copies the other ~138 packages' dist trees over identical bytes.
Fix
Stamp each package's
distwith the source hash it was built from (.webiny-build-hash). On a cache hit:clear-dist/rm -rf distremoves the marker too, so a forced clean still restores correctly.Measured (
yarn build, 139 cache hits, full cache)Before/after measured apples-to-apples via
git stashon the same machine and cache. The ~13s was almost entirelysystime (file copy).Scope
Three files under
scripts/buildPackages/. Build semantics unchanged — only the redundant restore-copy is skipped. The single-package build path now also records the source hash in build meta (it didn't before), making single-package builds cache-consistent.Verification
Hand-driven via
yarn build: no-op, single-edit (output correct in.js+.d.ts), cache-hit restore-copy path, and rebuild-when-cache-miss. Project test/preflight suite (adio/format/lint/sync-dependencies) run; fullyarn testnot run.🤖 Generated with Claude Code