Optimizing and Debugging Incremental Build Time in Swift 5.5

If your incremental (i.e. Debug) builds seem to be too slow, here some things to try (in no particular order):

  • In Xcode, go into the Report Navigator and examine your build log to see what's going on and where the time might be going.

  • See if some stage of your build is always replacing an imported file,

  • In "Other Swift Flags", add -driver-show-incremental and -driver-show-job-lifecycle. Then expand the build log portions of the "Compile Swift Source Files" build log entry. These options will cause the compiler to emit "remarks" explaining why the compiler decided to compile files.

  • If you are making lots of changes to top-level types, the incremental system won't be able to be as selective as possible. If you wrap one or more top-level types in an enclosing type, protocol, or extension, the compiler can be more selective.

12 Likes

More things to check:

In the build log, click on the hamburger all the way on the right of an "CompileSwiftSources" line, to expose the command-line-invocation of the compiler. Copy and paste the long invocation line into a text editor, and look for any of the following:
-incremental (you want),
-enable-batch-mode (you want),
-disable-batch-mode (you don't want),
-wmo (you don't want), and
-whole-module-optimization (you don't want).

If you see any problems, there's an issue with your build settings.

When looking at the build log, make sure you have "Recent" and "All Messages" selected, as shown below. (It seems obvious, but when tired, I have made this mistake myself.)

Terms of Service

Privacy Policy

Cookie Policy