r/Xcode • • 1d ago

I made a tool to share Xcode build caches across git worktrees

I made this for personal use but I thought I'd make it available for others too.

Basically I have a 512GB Mac and I am often very close to running out of disk space on it. I switch worktrees a lot when I'm reviewing or testing changes and I end up with a separate DerivedData or .build folder for each one. I also spend a few minutes rebuilding the same deps whenever I build in a fresh worktree.

So I wrote a tool lets my worktrees share build caches, called Warm: https://github.com/theblixguy/warm-worktrees

The core idea here is to take advantage of a feature called block cloning on your filesystem. The tool uses it so copies of the build caches share disk space until their files change and only those changes occupy any additional disk space. If a dependency changes then Xcode can just fetch or rebuild what it needs and then reuse the rest.

Here's a graph to illustrate the improvements:

Now if you're using a different build system like Bazel or etc you probably don't need this tool as they already offer a shared cache feature, but I didn't want to change build systems nor want to make others do it.

This is also a general-purpose, cross-platform (macOS and Linux) tool so you can use it with Xcode, SwiftPM, etc or with other languages like Rust, TypeScript and etc so it's a single tool across all your various projects. It's highly customisable as well and can be easily integrated into your workflows, especially if you're using AI agents.

If you have any thoughts or feedback or if this tool helps you please let me know, thanks!

3 Upvotes

4 comments sorted by

1

u/dawedev 13h ago

How do you clean up when a worktree gets removed? With clones it's hard to tell how much space deleting one actually frees, since du counts the shared blocks in every copy.

1

u/suyashsrijan 8h ago

When you remove a worktree, Warm will keep the build checkout so you can reuse it with another worktree. You can run warm pool prune --keep 1 (for example) to keep the most recently used checkout and remove the other idle ones.

You can also set minFreeGiB: X in your config to prune before builds. Warm will start with the least recently used idle checkout and check free space after each deletion (since du counts shared blocks in each copy) and it'll stop once there's X GiB free or report the shortfall and go ahead with the build.

1

u/dawedev 8h ago

Checking free space after each deletion instead of trusting du is the right way around it. Pruning against minFreeGiB right before a build is a nice touch too.

2

u/builtinswift 16h ago

using the filesystem instead of switching build systems, smart