Speed up Xcode Swift build times

后端 未结 5 672
难免孤独
难免孤独 2021-02-04 17:30

As my project has grown over the past year, so have its build times. Over the last few months it\'s gone from 4 minutes to around 7 (time includes GitHub pull, unit tests, etc).

相关标签:
5条回答
  • 2021-02-04 17:51

    Checkout this great post: https://github.com/fastred/Optimizing-Swift-Build-Times

    Some contents included:

    • Type checking of functions and expressions
    • Slowly compiling files
    • Build active architecture only
    • dSYM generation
    • Whole Module Optimization
    • Third-party dependencies
    • Modularization
    • XIBs
    • Xcode Schemes
    • Use the new Xcode build system
    • Enable concurrent Swift build tasks
    • Showing build times in Xcode
    0 讨论(0)
  • 2021-02-04 17:56

    Since Xcode 9.3 there is a Compilation Mode called Single File. It's explicitly said that it can change a game when talking about compilation times in the Xcode release notes

    The choice for compiling Swift code by file or by module moved from the Optimization Level setting to Compilation Mode, which is a new setting for the Swift compiler in the Build Settings pane of the Project editor. Previously this choice was combined with others in the Optimization Level setting. Compiling by file enables building only the files that changed, enabling faster builds. Compiling by module enables better optimization.

    It truly is a life saver. My incremental compilation times for enterprise project was decreased to couple of seconds. You can try it.

    EDIT: In Xcode 12, the same can be referred as Incremental

    0 讨论(0)
  • 2021-02-04 18:07

    Turning on the Whole Module Optimization while adding -Onone in Other Swift Flags worked for me, it reduced compilation time to 3 minutes from 10.
    Read more here - Speed Up Swift Compilation

    I'm using Swift 3 on Xcode 8.3.

    0 讨论(0)
  • 2021-02-04 18:13

    Xcode 8.1/Swift 3.1 adds some relief for projects including some ObjC. Precompiled headers are back! https://swift.org/blog/bridging-pch/

    If your project includes a bridging header, this will help. (In Xcode 8.1 beta 4 and later, this is the default; in prior betas add -enable-bridging-pch to Other Swift Flags).

    0 讨论(0)
  • 2021-02-04 18:14

    Here's an article about benchmarking/speeding up compilation time - swift-profiling.

    In case it goes dead here is the tldr:

    xcodebuild -workspace App.xcworkspace -scheme App clean build OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" | grep .[0-9]ms | grep -v ^0.[0-9]ms | sort -nr > culprits.txt
    

    You can just run that or add the following flags to your build under the other-swift-flags in build settings:

    -Xfrontend -warn-long-function-bodies=100
    

    This will show you which lines are slowing down your compile time.

    0 讨论(0)
提交回复
热议问题