Skip to content

perf(build): skip redundant cache copy when dist is already fresh#5409

Merged
adrians5j merged 2 commits into
nextfrom
claude/build-skip-redundant-cache-copy
Jul 15, 2026
Merged

perf(build): skip redundant cache copy when dist is already fresh#5409
adrians5j merged 2 commits into
nextfrom
claude/build-skip-redundant-cache-copy

Conversation

@adrians5j

Copy link
Copy Markdown
Member

Problem

Every yarn build restores each cache-hit package by fs.copySync-ing its cached output into disteven when dist already 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 dist with the source hash it was built from (.webiny-build-hash). On a cache hit:

  • if the marker already equals the current source hash → skip the copy (bytes already on disk)
  • otherwise copy from cache and re-stamp (fresh checkout, deleted/stale dist)

clear-dist / rm -rf dist removes the marker too, so a forced clean still restores correctly.

Measured (yarn build, 139 cache hits, full cache)

scenario before after
no-op 14–17s ~2s
edit one file ~15s ~3s
deleted dist ~15s ~2s (restores just the missing one)

Before/after measured apples-to-apples via git stash on the same machine and cache. The ~13s was almost entirely sys time (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; full yarn test not run.

🤖 Generated with Claude Code

adrians5j and others added 2 commits July 15, 2026 07:40
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>
@adrians5j
adrians5j merged commit a8d7290 into next Jul 15, 2026
115 checks passed
@adrians5j
adrians5j deleted the claude/build-skip-redundant-cache-copy branch July 15, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant