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.

  1. A Swift file takes forever to compile. How do you find the cause and fix it? 5.6.1 · L3
    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.

  1. How does incremental compilation decide what to rebuild, and why does a small edit sometimes rebuild half the app? 5.6.2 · L5
    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