perf: use darwin's clonefile syscall #893
Merged
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.
This can save time and disk-space when copying files around on the same device. File clones (aka reflinks) share backing disk blocks; they differ from hardlinks in that inodes are not shared and the contents are copy-on-write.
The Go standard library (as of v1.22) will arrange to do a similar thing for file copies on Linux (see: https://cs.opensource.google/go/go/+/refs/tags/go1.22.6:src/os/zero_copy_linux.go;l=53). Unfortunately, Mac OS' more limited API is less amenable to that form of transparent wrapping.
Changes are visible to end-users: no
Test plan
Manually confirmed that cloned files differ in inode but share backing blocks with a custom script (gist).
Before
After
Note: source and cloned file differ in inode but contents share a location on disk. This relationship can be broken by making edits to the source file (exercising transparent copy-on-write).