Skip to content

Reflink shared/copy subtrees in a single syscall#22

Merged
bkildow merged 1 commit into
mainfrom
perf/apply-copy-tree-reflink
Apr 24, 2026
Merged

Reflink shared/copy subtrees in a single syscall#22
bkildow merged 1 commit into
mainfrom
perf/apply-copy-tree-reflink

Conversation

@bkildow
Copy link
Copy Markdown
Owner

@bkildow bkildow commented Apr 24, 2026

Summary

  • ApplyCopy now tries a single clonefile(2) per template-free top-level directory in shared/copy/ via a new fscopy.CopyTree, collapsing the ~20k per-file reflinks for a Composer vendor/ into one syscall.
  • Falls through to the existing per-file WalkDir + CopyFile path for top-level files, subtrees containing .template files, destinations that already exist, and any filesystem/platform that returns errReflinkUnsupported (Linux FICLONE is file-only and stays on the per-file path).
  • wt add --skip-setup in a 20,762-file project: 6.18s → 2.04s wall-clock, 4.94s → 0.98s system CPU.

Test plan

  • make dev (fmt + vet + test + build)
  • GOOS=linux go build ./... cross-compile
  • New unit tests: TestCopyTreeNested, TestCopyTreePreservesSymlink, TestCopyTreeExistingDst, TestIsReflinkUnsupported in fscopy; TestApplyCopyFastPathForDirectories, TestApplyCopyFallsBackWhenTreeContainsTemplate, TestApplyCopyFastPathPreservedWhenVarsNil in project
  • Timed against a real 20k-file vendor/ in ~/Sites/affiliated with --skip-setup — pause after copied vendor/ is gone

ApplyCopy previously walked every file under shared/copy/ and reflinked
each one individually — ~4 syscalls per file, so a Composer vendor/ with
20k files took ~4s of pure syscall overhead after "copied vendor/"
printed. APFS clonefile(2) accepts directories and clones the whole
hierarchy in one syscall, so fast-path each template-free top-level
subtree via a new fscopy.CopyTree and fall through to the existing
per-file walk for top-level files, template-containing subtrees,
pre-existing destinations, and non-APFS/Linux volumes.

Measured 6.2s → 2.0s wall-clock for `wt add --skip-setup` in a 20,762-file
project; system CPU drops 4.94s → 0.98s.
@bkildow bkildow merged commit 397bb77 into main Apr 24, 2026
@bkildow bkildow deleted the perf/apply-copy-tree-reflink branch April 24, 2026 21:00
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