Is the fast build time too long when the config is "freed"?

I have an open source project and the file count in the project is over 40.

I create a project when the config is Debug

compile time 2m22s

. And I also use BuildTimeAnalyzer , longest time ever 28ms

.

But when I create a project with config Release

it gets stuck for Compile Swift source files

over one hour.

I have no idea about this, please help me.

+3


source to share


2 answers


In a DEBUG build, if you add up all the time it took for each function, you get about 7 seconds. The numbers don't quite add up - you spent 142s building everything, but these functions take about 7 seconds to compile.

This is because this time is just checking the type of each function body. The Swift frontend has three flags that you can use:

  • -Xfrontend -debug-time-compilation

  • -Xfrontend -debug-time-function-bodies

  • -Xfrontend -debug-time-expression-type-checking

Let me be the first to see the whole picture. Pick one slow file, say Option.swift

and see:

===-------------------------------------------------------------------------===
                               Swift compilation
===-------------------------------------------------------------------------===
  Total Execution Time: 30.5169 seconds (43.6413 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
  23.5183 ( 80.1%)   0.7773 ( 67.6%)  24.2957 ( 79.6%)  34.4762 ( 79.0%)  LLVM output
   3.7312 ( 12.7%)   0.0437 (  3.8%)   3.7749 ( 12.4%)   5.4192 ( 12.4%)  LLVM optimization
   1.8563 (  6.3%)   0.2830 ( 24.6%)   2.1393 (  7.0%)   3.1800 (  7.3%)  IRGen
   0.2026 (  0.7%)   0.0376 (  3.3%)   0.2402 (  0.8%)   0.4666 (  1.1%)  Type checking / Semantic analysis
... <snip> ...
  29.3665 (100.0%)   1.1504 (100.0%)  30.5169 (100.0%)  43.6413 (100.0%)  Total

      

Turns out it's not fast, but slower, but LLVM! So there is no point in looking at the type check time. We can further check why LLVM is slow by using it -Xllvm -time-passes

, but it won't give us useful information, just speaking it X86 Assembly / Object Emitter

takes longer.

Take a step back and check which files are taking the longest to compile:

Option.swift             30.5169
Toolbox.swift            15.6143
PictorialBarSerie.swift  12.2670
LineSerie.swift           8.9690
ScatterSerie.swift        8.5959
FunnelSerie.swift         8.3299
GaugeSerie.swift          8.2945
...

      



Half a minute spent on Options.swift

. What's wrong with this file?

  • You have a huge structure with 31 members. It takes 11 seconds to compile just this structure.
  • You have a huge listing with 80 options. This enum takes 7 seconds to compile.

The first problem is easy to fix: Use final class

instead!
The second problem won't have an easy fix (I don't see any time improvement with alternatives like replace enums with a hierarchy class). All other slow files have a similar problem: large structure, large enums.

Just replacing everything struct

with final class

just enough to make the compile time "over time and still be compiled" to "2.5 minutes".


See also Why choose structure over class? ... Your "structure" cannot count as struct

s.

Note that changing from struct

to a class changes the semantics of the user code as classes have reference semantics.

+2


source


Try this .... under Build Settings

Swift Compiler - Code Generation

for Release

select SWIFT_OPTIMIZATION_LEVEL = -Owholemodule

. Then under Other Swift Flags

enter -Onone

. By doing this, they carved out large chunks of time from my project.



0


source







All Articles