5.6 · Why it compiles slowly, and what rebuilds
“Why is this slow to compile?” is the most common compiler question in a real codebase. The answer is nearly always one of a small set of causes, and each has a flag that finds it.
Mental model. Measure before guessing. The compiler will tell you which expression, which function and which file costs the time.
Slow type checking
Expressions the solver struggles with, and how to find them.
- A Swift file takes forever to compile. How do you find the cause and fix it?
First measure. The Xcode Build Timeline shows which files and phases dominate. Inside a file, ask the compiler to name the culprit: -Xfrontend…
What gets rebuilt
Dependency tracking and how to keep changes local.
- How does incremental compilation decide what to rebuild, and why does a small edit sometimes rebuild half the app?
The compiler records, for each file, what it provides (the declarations it defines) and what it depends on (the declarations it uses, by name). After an edit…
More in Compiler & language internals
- 5.1 · From source to machine code, and how to look inside
- 5.2 · Devirtualisation, whole-module optimisation, inlining, exclusivity
- 5.3 · Specialisation, witness tables, and opaque vs existential in the compiled code
- 5.4 · Library evolution, module interfaces, and the ABI boundary
- 5.5 · How Swift macros work, and the roles they play
- 5.7 · Swift 6 language mode and upcoming features
- 5.8 · Symbol names, linkage, lazy globals and reflection metadata: what is in the binary
- 5.9 · Optimisation levels, closure contexts, ownership conventions and value layout
- 5.10 · What property wrappers, result builders, async and throws compile to
- 5.11 · Package access, SPI, internal imports, strict memory safety and pre-specialisation