Pocket How
Xcode and tooling

Speed up Xcode build times: measure, then fix what costs the most

Xcode 26 and later, iOS and iPadOS projects. Intermediate. By Cihat Salik, .

Short answer

Measure first with Product > Perform Action > Build With Timing Summary and the -warn-long-function-bodies frontend flag. Then fix run scripts that run every build, slow type-checking, module variants caused by mismatched settings, and serial target graphs. Turn on Enable Compilation Caching (Xcode 26+) to speed up clean builds and branch switches.

Why your builds feel slow

Most slow Xcode builds come from a few causes. A script runs on every build, a handful of Swift functions take seconds to type-check, the same module gets compiled several times with different flags, or targets are chained so tightly that Xcode can’t use all your cores. Developers tend to try random fixes first: they delete DerivedData, flip build settings they read about in a 2017 post, or buy a faster Mac. This guide goes the other way round. You measure, find the biggest item, fix it and measure again.

Measure before you change anything

Take two baselines

You need two numbers, because they answer different questions.

  • Clean build. Choose Product > Clean Build Folder, then build. This is what CI and a fresh checkout pay.
  • Incremental build. Change one line in a file you edit often, then build. This is what you pay dozens of times a day.

Antoine van der Lee makes the same point in his build performance write-up: start from a clean build so cached products don’t distort the baseline, and measure incremental builds too, since that’s where most of your day goes. Write both numbers down with the Xcode version and the Mac you used. Build times change with every Xcode release, so a number without that context means little a few months later.

Use the timing summary and the timeline

Apple’s incremental build guide starts in the same place. Choose Product > Perform Action > Build With Timing Summary, then select that build in the Report navigator. The summary groups time by task type, so you can see right away whether Swift compilation, linking, asset compilation or a script dominates.

From the command line, pass -showBuildTimingSummary:

xcodebuild -scheme MyApp \
  -destination 'generic/platform=iOS Simulator' \
  -showBuildTimingSummary \
  build | tail -40

The summary adds up time across tasks that ran in parallel, so the total can be larger than the wall-clock build time. That’s expected. For the wall-clock picture, open the build log and show the timeline in the assistant editor. It lays tasks out by parallelism. Look for long bars with nothing beside them, because those are the places where your Mac sat idle waiting on one task. In an incremental build the timeline shows only the tasks that actually ran, so a single long bar there is often a script or one slow file.

The timing summary also lists every module Xcode built and the option differences between variants of the same module, which you need later for explicit modules.

Find slow type-checking

Swift’s type checker is the usual reason one file takes far longer than its neighbours. Two frontend flags make the compiler warn about the culprits. Add them under Other Swift Flags (OTHER_SWIFT_FLAGS) for the Debug configuration:

-Xfrontend -warn-long-function-bodies=100
-Xfrontend -warn-long-expression-type-checking=100

The numbers are milliseconds. Each function body or expression that takes longer gets a warning with its location, so you can jump straight to the code. Start at 100, fix what shows up, then lower the threshold. These flags are compiler development options that Apple doesn’t document for app developers, so treat them as a diagnostic you turn on while investigating and remove afterwards. They add warning noise and don’t make the build faster.

Fix the expensive things first

Scripts that run on every build

By default Xcode runs a Run Script phase on every build, including incremental ones, and runs it serially with other tasks. Apple’s guide lists the rule: Xcode runs the script when it has no input files, no output files, when an input changed, or when an output is missing. Declare at least one input and one output for each script, using .xcfilelist files when the lists are long. A script that needs no input still benefits from a file that never changes as its input, and a script with no output can write a stamp file.

Then ask whether the script needs to run in Debug at all. Van der Lee found a dSYM upload to a crash reporter running on every debug build and gained several seconds per build by limiting it to Release. A linter that checks the whole project on every build is the other common offender. Run it only on changed files, or move it to a git hook or CI.

if [ "${CONFIGURATION}" != "Release" ]; then
  exit 0
fi
"${SRCROOT}/scripts/upload-symbols.sh"

With User Script Sandboxing on (ENABLE_USER_SCRIPT_SANDBOXING), Xcode knows exactly which files a script reads and writes, which is what allows it to schedule scripts safely alongside other work.

Type-checking hot spots

When the frontend warnings point at a function, the fix is nearly always to give the compiler less to infer. Apple’s coding practices article lists the patterns:

  • Annotate complex initial values. A property initialised from a reduce or a chain of generic calls makes the compiler solve for the type. Write the type.
  • Break up long expressions. Long chains of ??, ternaries and mixed numeric literals blow up the solver. Split them into named intermediate values.
  • Use explicit delegate protocols. A weak var delegate: AnyObject? that you call methods on forces a project-wide lookup. A protocol type doesn’t.
  • Keep bridging headers small. In mixed Swift and Objective-C targets, every header in the bridging header and every public symbol in the generated Swift header costs time in every file.

Here is the kind of rewrite the warnings lead to:

struct OrderSummary {
    let lineTotals: [Double]
    let discount: Double?
    let taxRate: Double

    var total: Double {
        let subtotal: Double = lineTotals.reduce(0, +)
        let discounted: Double = subtotal - (discount ?? 0)
        let tax: Double = discounted * taxRate
        return discounted + tax
    }
}

Written as one expression with untyped literals and an optional in the middle, the same calculation can take the type checker far longer. Split into typed steps, it’s trivial. SwiftUI views are the most common place for this. A body that builds a long chain of modifiers with inline conditionals is one big expression, and splitting it into small subviews helps compile time as well as readability.

Explicit modules

Since Xcode 16, the build system can schedule module builds as explicit tasks: it scans dependencies, builds each Clang and Swift module once in dependency order with unrelated modules in parallel, then compiles your sources. The Xcode 26 release notes make explicit modules the default for all Swift targets, except targets using Swift versions before 5 or Swift/C++ interoperability. If a project hits severe problems, it can opt out with SWIFT_ENABLE_EXPLICIT_MODULES = NO. Treat that as a temporary escape hatch and file feedback, because opting out also loses the debugger speedups that explicit modules bring.

The build-time win depends on how many variants of each module you build. Apple’s explicit modules article explains that a module has to be rebuilt for each distinct set of compiler options its importers use. Two targets with the same dependencies but different GCC_PREPROCESSOR_DEFINITIONS can’t share built modules. Open the Build With Timing Summary report, look for modules built more than once, and read the option differences it lists. Most of the time the fix is to move a per-target setting up to the project level or into a shared .xcconfig, so every target compiles with the same flags.

Xcode 27 sped up the Swift dependency scanner, and the Xcode 27 release notes warn about a side effect: every Clang module reachable from one scan must have a unique name. A vendored library that ships a module.modulemap redeclaring an SDK module, or two copies of the same module on the header search path, now produces a scan error. Remove the duplicate.

Compilation caching

Xcode 26 added compilation caching as an opt-in feature for Swift and C-family languages. It stores compilation results keyed by their inputs and, when it sees the same inputs again, reuses the result. Apple’s release notes name the two workflows that benefit most: switching branches and clean builds. Turn it on with the Enable Compilation Caching build setting (COMPILATION_CACHE_ENABLE_CACHING = YES) or in the per-user project settings.

xcodebuild -scheme MyApp \
  -destination 'generic/platform=iOS Simulator' \
  COMPILATION_CACHE_ENABLE_CACHING=YES \
  build

The cache Xcode creates is local to the machine. Sharing it across a team or CI fleet needs a remote cache service. The Tuist Xcode cache guide shows the settings involved, including COMPILATION_CACHE_ENABLE_PLUGIN and COMPILATION_CACHE_REMOTE_SERVICE_PATH, and notes that without the remote service path only Swift compilations are shared. It also documents prefix mapping settings for Xcode 27 that make cache keys independent of the checkout path, and a coverage caveat: sources compiled with prefix mapping can be missing from xccov reports.

Results vary. Remote-cache vendors publish large gains, while developers on the Swift Forums report CI machines where turning caching on changed nothing, and one reply in that thread found the real cause was a thermally throttled Mac mini. Turn caching on, measure a clean build and a branch switch before and after, and keep it if the numbers improve. Don’t expect it to speed up the one-line incremental build, which was already reusing previous work.

Target and package structure

Xcode builds as much in parallel as your dependency graph allows. Apple’s guide gives the levers:

  • Keep dependencies accurate. Missing dependencies cause wrong builds. Unnecessary ones force targets to wait on each other.
  • Break up monolithic targets. If a feature module imports a large utilities module and uses a small part of it, every change to utilities rebuilds the feature. Smaller modules with narrow dependencies rebuild less.
  • Split tests by target. One test target that depends on the app, an extension and a framework can’t start until all three finish.
  • Set the scheme’s Build Order to Dependency Order if the timeline shows targets building one after another for no reason.

More modules isn’t automatically faster. Each module adds scanning, linking and planning work, and Apple’s own guide warns that more targets add complexity and asks you to measure the result. Split where the timeline shows a long serial chain, or where a frequently edited module forces large rebuilds.

Macro packages deserve a special look, because they depend on swift-syntax, which is large. Xcode 26 has a swift-syntax prebuilts feature for macros, and its release notes mention the IDEPackageEnablePrebuilts user default in a workaround for a preview issue. If swift-syntax compiling from source dominates your clean-build timeline, check whether that feature applies to your setup before restructuring anything.

For very large codebases, the ceiling of a single Xcode build graph becomes the problem. Spotify’s Patrick Balestra describes in Switching Build Systems, Seamlessly how the iOS app moved to Bazel with remote caching and remote execution, keeping Xcode as the editor through rules_xcodeproj, and cut the CI feedback loop from about 80 to about 20 minutes. That’s a multi-team project with a dedicated build infrastructure group. For most apps, the fixes above get you most of the way without changing build systems.

DerivedData myths

Deleting DerivedData speeds up builds. It does the opposite. It throws away every build product and index, so the next build is a clean build. Deleting it is a valid fix when the build is in a corrupt state, such as stale module errors after an Xcode update, and it’s never an optimisation.

A fixed DerivedData path on CI gives you incremental builds. The developer in the forum thread above tried exactly that, with compilation caching on, and saw no change in CI time. A CI machine that checks out code fresh, switches Xcode versions or runs jobs from different branches rarely matches what the old DerivedData recorded. Compilation caching keyed by content is the tool designed for reuse across runs, and you still have to measure that it works on your runners.

Old build settings still matter. Van der Lee’s article notes that Xcode now defaults to the settings people used to tune by hand: incremental compilation and -Onone for Debug, whole-module optimisation for Release, and Build Active Architecture Only for Debug. Projects created years ago can still carry overrides. Search your build settings for values that differ from the defaults, and delete the overrides you can’t justify.

Previews make the build slower. An Apple engineer explains in a developer forums thread that since Xcode 16, previews share build products with Debug builds instead of building in a separate area, so they no longer double your build work. If previews feel slow, the cause is usually the same scripts and type-checking issues covered above.

Checklist

Step What to check Where
Baseline Clean and incremental times, Xcode version, Mac Report navigator
Scripts Inputs and outputs declared, Debug-only work skipped Build Phases
Type-checking Warnings from -warn-long-function-bodies Other Swift Flags, Debug only
Module variants Modules built more than once and why Build With Timing Summary
Duplicate modules Unique Clang module names across search paths Xcode 27 scan errors
Caching Clean build and branch switch, with and without COMPILATION_CACHE_ENABLE_CACHING
Graph Long serial chains in the timeline Assistant timeline, scheme Build Order
Overrides Build settings that differ from defaults Build Settings, Levels view

Re-measure after each change, one at a time. Two fixes applied together can hide the fact that one of them made the build slower.

Sources and further reading

Read next