Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build Time Optimization - Swift Bangalore #9

Swift India
September 22, 2018

Build Time Optimization - Swift Bangalore #9

Swift India

September 22, 2018
Tweet

More Decks by Swift India

Other Decks in Technology

Transcript

  1. Build time - before 0 125 250 375 500 Before

    0 125 250 375 500 Before Clean Build Incremental Build 448 sec 170 sec Average
  2. How we reduced the build time? Optimisation of swift code

    • Explicit type declaration ❌ let a = [“aab”, “b”, “c”] ✅ let a: [String] = [“aab”, “b”, “c”] • Use precomputed value ❌ if number == 30 * 30 { // do something } ✅ if number == 900 { // do something } • Avoid nil-coalescing and ternary operator (although I like to use them) • Declaring functions private or fileprivate • Declaring non inheritable classes final • Breaking complex functions
  3. How we reduced the build time? Optimisation of swift code

    Changing few flags in build settings of Xcode Project • Build Active Architecture Only → set to YES for debug • Build Options → DEBUG INFORMATION FORMAT is set to DWARF • Swift Compiler —  OPTIMIZATION LEVEL → to -Onone • Set user defined flag to SWIFT_WHOLE_MODULE_OPTIMIZATION to YES
  4. Build Time - after phase 1 0 125 250 375

    500 Before After 0 125 250 375 500 Before After Clean Build Incremental Build 448 sec 278 sec 170 sec 90 sec Average
  5. • The code was split into individual modules which were

    not dependent on each other. • Using tools to generate projects on demand with only the requested module. • Making it easier for the developer to generate code using these tools - written script to generate and reset the project • Tools used • XCake (Deprecated) • XcodeGen How did we further reduce the build time?
  6. Build Time - Final 0 125 250 375 500 Before

    After Modularisation 0 125 250 375 500 Before After Modularisation Clean Build Incremental Build 448 sec 278 sec 253 sec 170 sec 90 sec 15 sec After modularisation Average
  7. Build Time - Final 0 125 250 375 500 Before

    After Modularisation After modularisation 0 125 250 375 500 Before After Modularisation Clean Build Incremental Build 448 sec 227 sec 137 sec 170 sec 79 sec 12 sec Xcode 10 Average