Swift compile times comparison: frameworks vs. non-frameworks

Hi all,

In my continued investigation of Swift compile times I was able to gather
some interesting data.

In the last couple weeks we decided to put in a large dev effort to move
our entire codebase into frameworks. We'd been having really slow build
times (often 5 minutes for an incremental compile, 12 minutes for a clean
build) and decided it was worth the effort to clean it up.

I had expected that moving code into frameworks would substantially speed
up the incremental compile time, but didn't expect it to speed up the clean
compile. To my surprise, it sped up the incremental compile to less than a
minute in most cases and just a little over 2 minutes for a clean build.

Investigating further, I added the -debug-time-function-bodies flag and
parsed out the build times for individual functions- following the
instructions from: Profiling your Swift compilation times ยท Bryan Irace Looking at our code pre-
and post- frameworks move (and pre-frameworks actually had about 10% of the
code in frameworks) I got the following results:

*Pre-frameworks:*

9842 functions compiled.

1463 unique functions compiled

8379 of the functions compiled were duplicates

*Post-frameworks:*

2805 functions compiled.

1288 unique functions compiled

1517 of the functions compiled were duplicates
So first, just want to say, that the frameworks solution really worked. It
has resulted in a huge increase in productivity, and I like our codebase
better. It's made me love Swift again.

I'm wondering though: is this a known/expected result? I was pretty
surprised by the amount of duplicated compiles but I'm not experienced in
this area so maybe that's normal. Would love any clarification on how this
works.

Thanks so much!
Sam

Which compilation mode do you use? Singlefile or wholemodule, and if the latter, do you use the non-optimized variabt for debug builds? And did you try the new singlefile batch mode in Xcode 10 beta?

I wonder did you notice any seemingly unnecessary recompilations when you just change something small in a file that is part of a framework target? The Swift compiler currently does some unnecessary recompilations: https://mobile.twitter.com/klangwabe/status/1005408773001924609