Skip to content

perf(@astrojs/vercel): APFS clone for file copies + NFT dependency cache#15896

Open
nishantmodak wants to merge 1 commit intowithastro:mainfrom
nishantmodak:perf/vercel-apfs-clone-and-nft-cache
Open

perf(@astrojs/vercel): APFS clone for file copies + NFT dependency cache#15896
nishantmodak wants to merge 1 commit intowithastro:mainfrom
nishantmodak:perf/vercel-apfs-clone-and-nft-cache

Conversation

@nishantmodak
Copy link

Summary

On macOS, cp -rc uses clonefile(2) (APFS copy-on-write) which is ~3x faster than
Node.js cpSync for large directories. This PR applies that optimization to three
file copy operations in the Vercel adapter, and adds a persistent cache for the NFT
dependency trace.

Changes

APFS clone for large file copies (index.ts)

  • Static output copy (dist/client/.vercel/output/static/): was cpSync, now cp -rc on macOS
  • Server output copy (dist/server/.vercel/output/_functions/): same

NFT dependency cache (lib/nft.ts)

  • Caches the list of node_modules/ files traced by @vercel/nft, keyed by sha256(package-lock.json)
  • On cache hit, skips nodeFileTrace entirely (saves ~1-2s)
  • Separately caches the function's assembled node_modules/ dir using APFS CoW clone
  • On full cache hit: restores func node_modules/ via clone (~50ms vs ~900ms) and clones dist/server/ into the bundle

Benchmark (last9/last9.io — 273 pages, hybrid output)

Step Before After
NFT trace (cold) ~2s ~2s (unchanged)
NFT trace (warm) ~2s ~0.05s (skipped)
_functions/ file copy (warm) ~900ms ~50ms
runHookBuildDone total (warm) ~2100ms ~870ms

All changes fall back gracefully on non-macOS platforms or when cp is unavailable.

Non-goals

  • No behavior change on Linux/Windows (falls back to existing cpSync path)
  • Cache is keyed conservatively (package-lock.json hash) — any dep change invalidates it

On macOS, replace cpSync with cp -rc (APFS clonefile CoW) for the
static output and _functions directory copies. Add a persistent cache
for the NFT dependency trace (keyed by sha256 of package-lock.json)
and a clone cache for the assembled func node_modules dir.

All changes fall back gracefully to the existing cpSync path on
non-macOS platforms or when cp is unavailable.
@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2026

🦋 Changeset detected

Latest commit: 04ae8e3

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant