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

Build Time Optimization - Swift Bangalore #9

Eeb061c8b2816b771920da1b3e7904a3?s=47 Swift India
September 22, 2018

Build Time Optimization - Swift Bangalore #9

Eeb061c8b2816b771920da1b3e7904a3?s=128

Swift India

September 22, 2018
Tweet

Transcript

  1. Build time optimisation Practo Pro App Rohit Pal
 Senior iOS

    Engineer , Practo
  2. None
  3. You, after a while

  4. Your manager during a critical bug fix.

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

    0 125 250 375 500 Before Clean Build Incremental Build 448 sec 170 sec Average
  6. 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
  7. 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
  8. 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
  9. How did we further reduce the build time?

  10. • 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?
  11. 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
  12. 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
  13. After modularization developer productivity

  14. Big shout to amazing Practo Pro iOS Team

  15. Thank You! Reach out to me : Medium GitHub LinkedIn