Our project now has over 50 local Swift packages and our clean build time is reaching 15 minutes. This is killing our productivity. We are already using an M2 Max, so hardware isn't the issue. What are some compiler flags, build settings, or modularization strategies (like using XCFrameworks) that can help reduce incremental and clean build times in Xcode?
3 answers
Build times are the silent killer of dev velocity. First, check your "Build Settings" and ensure "Build Active Architecture Only" is set to Yes for Debug. Second, look at your "Optimization Level"; it should be 'None' for Debug. A huge win we had in 2024 was converting our stable, low-level modules into pre-compiled XCFrameworks. If a package hasn't changed in months, there’s no reason the compiler should look at it every time you do a clean build. Also, use the "Build Timing Summary" in Xcode to identify exactly which functions are taking the longest to type-check—sometimes a single complex line of code can add seconds to the build.
Have you tried using a remote caching tool like 'Bazel' or 'Tuist' to share build artifacts across your team’s machines to avoid redundant compilation?
Avoid using too many complex generics and nested type inference in your code. Swift's type checker struggles with those, which can significantly slow down compilation.
I’ve seen this firsthand. Explicitly declaring the type of a variable instead of letting the compiler guess it can sometimes shave milliseconds off every file, which adds up!
Mark, we recently moved to Tuist and it has been a revelation. It generates the Xcode projects on the fly and handles the caching of binaries beautifully. Our clean build times went from 15 minutes down to about 3 minutes for most developers because they only compile the code they are actually changing. It requires some DevOps effort to set up, but the ROI in terms of developer happiness and saved hours per week is well worth the initial complexity.