# incremental compilation

**URL:** <https://forums.swift.org/t/incremental-compilation/1242>\
**Category:** Compiler\
**Created:** [January 29, 2016, 10:27pm UTC](https://forums.swift.org/t/incremental-compilation/1242 "2016-01-29T22:27:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik\_Eckstein](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/erik_eckstein/32/320_2.png) [@Erik\_Eckstein](https://forums.swift.org/u/Erik_Eckstein)\
**Post date:** [January 29, 2016, 10:27pm UTC](https://forums.swift.org/t/incremental-compilation/1242/1 "2016-01-29T22:27:02Z")

</div>

I'd like to give some additional information about my recent commit [Incremental compilation for the llvm part of the compiler. · apple/swift@aaaf36e · GitHub](https://github.com/apple/swift/commit/aaaf36e83521f153ba4b0720795efe4980d9b124)  
The idea is to run the swiftc's llvm-pipeline only if the llvm IR (the output of IRGen) did change. The llvm pipeline takes about 45% to 60% of total compilation time.  
It's done by storing a MD5 hash of the IR in the generated object files. Specifically, on macho-o the hash is stored in a special section in the \_\_LLVM segment, which is ignored by the linker.

The intention is to speed-up whole module compilation. We are already running the llvm part multi-threaded, which gives us about 30% speedup with 4 cores. Incremental gives us another 15% to 20%, assuming only a "small" thing changed in one of many files.  
Of course the incremental speed-up totally depends on what changes are done on the sources. In worst case a small change might trigger a complete re-compilation e.g. if it's in an often inlined function.

Here are some numbers for three different modules: a 64 file module which quite large files, a 500 file module with smaller files and the Adventure project. The percentages are similar for all three modules.

A nice side-effect of incremental compilation is that it works for every type of compilation which produces an object file (not only for multi-threaded wmo). For example if you make changes in the compiler which do not affect code generation, then a library build (ninja swift-stdlib) is faster by 60%.

One additional note about the hash. It also includes the full compiler version, which contains e.g. the git SHAs (in a development build). So every time the branch head changes, everything is recompiled.  
The hash also includes some option settings, like -disable-llvm-optzns.  
There is only one situation where you should think of incremental compilation: if you make some local changes in swiftc's llvm-pipeline you should explicitly clean all compiled libraries, etc.

Erik

![](https://global.discourse-cdn.com/swift/original/2X/7/7e067240b29079be9496782c17d5e56e696c4b3c.png)

![](https://global.discourse-cdn.com/swift/original/2X/b/b1822a5edff63072dbbeed44187b40ae279742ff.png)

![](https://global.discourse-cdn.com/swift/original/2X/3/3d2881f7b53cc67d295d05b98878a147f596e57e.png)

![](https://global.discourse-cdn.com/swift/original/2X/2/2cdccbb01f7a1fa056e73ade8cd8793ba468b275.png)
