3 ms·
I've found a use for APFS' copy-on-write cloned files. I like to work with git worktrees, and I work on an app that has a large (2 gb) node_modules directory.
by llimllib 3y ago
I've found a use for APFS' copy-on-write cloned files.
I like to work with git worktrees, and I work on an app that has a large (2 gb) node_modules directory.
Previously, every time I made a worktree, I had to `npm install` to get a fresh node_modules, or copy the full directory, which was slow.
$ time /bin/cp -r node_modules /tmp/node_modules
/bin/cp -r node_modules /tmp/node_modules 1.98s user 58.26s system 63% cpu 1:34.17 total
The -c option to /bin/cp on a mac is "copy files using clonefile(2)", making clones instead of full copies. It's still not super fast, but almost a minute less of waiting for the copy is a nice improvement:
$ time /bin/cp -rc node_modules /tmp/node_modules_cloned
/bin/cp -rc node_modules /tmp/node_modules_cloned 0.43s user 29.85s system 79% cpu 38.211 total
The one downside is that GNU has an incompatible option for creating clones (`--reflink`), leading to this very ugly conditional:
https://github.com/llimllib/personal_code/blob/0e1034f13b31f8357c399d3159867601869e23de/homedir/.local/bin/worktree#L35-L58 https://github.com/llimllib/personal_code/blob/0e1034f13b31f...
- bandergirl 3y agoHas something changed in the Finder recently? I remember being able to copy my node_modules-containing folders relatively quickly but now it still takes a few seconds. I wonder if they either dropped that feature from Finder or if it has a hard time cloning many files
- lights0123 3y agoMoving forward, GNU coreutils 9.0, released September 2021, automatically uses reflinks when available. I still have several Ubuntu 20.04 systems that don't have that though, so your way is necessary for a bit.
- diroussel 3y agoUse pnpm, it hard likes the files in node_modules to a content addressable ‘store’. It makes ‘pnpm install’ pretty fast.