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

Tomasz Gebarowski & Wojciech Łukaszuk: SWIFT AT SCALE

Realm
October 22, 2016

Tomasz Gebarowski & Wojciech Łukaszuk: SWIFT AT SCALE

Is Swift ready for large scale business apps? We would like to share our experience on writing one of the most popular mobile banking apps in Poland. The mBank app, that is entirely written in Swift. The problems we faced, lessons learnt, pitfalls and benefits

Realm

October 22, 2016
Tweet

More Decks by Realm

Other Decks in Technology

Transcript

  1. 1. Wprowadzenie - Info o autorach - Kilka słów o

    aplikacji: - ilość linii kodu/klas/protokołów - historia przepisywania na Swift (kiedy się zaczęła, ile trwała, ile osób nad tym pracowało) 3. Co nam dał Swift? - Swift jest bezpieczniejszy (dzięki optionals, czyli weliminowalismy NPE) - Bardziej kompaktowa składnia - Krótsza ścieżka wdrożenia dla nowych devów (zwłaszcza na codzień piszacych w C#) - Genericsy, Enumy, Protocols - Swift jest szybszy (porównanie z ObjC, dynamiczne biblioteki) - Swift Playgrounds (szybkie prototypy) C) Analiza kompilacji poszczegolnych plikow (który kod powoduje dłuzsza kompilację)
  2. // Objective-C @interface Foo : NSObject @property (readonly) int bar;

    - (instancetype)initWithBar:(int)bar; @end @implementation Foo - (instancetype)initWithBar:(int)bar { self = [super init]; if (self) { _bar = bar; } return self; } @end // Swift struct Foo { let bar: Int }
  3. Faster build times No debug symbols Stepping behaves oddly Much

    slower build times No incremental builds * Incremental builds * supported since Swift 3 and Xcode 8 vs -Owholemodule -Onone
  4. Problem with Whole Module Optimisation getconf ARG_MAX 262144 uses absolute

    path of every Swift file in project +1500 Swift files Assume long project dir path MacOS command line
 max length
  5. Problem with -Onone Assuming we have 1500+ Swift files in

    project Single Swift file compilation takes about 1-2 seconds
  6. How did we approach the situation? Sources: http://irace.me/swift-profiling Profiling Swift

    compilation times 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 1 2 Inspecting culprits 58.2ms /Users/tomasz/workspace/iOS/Sources/FileA.swift:23:14 @objc get {} 59.8ms /Users/tomasz/workspace/iOS/Sources/FileA.swift:23:52 (closure)
  7. Compilation times -Onone -Owholemodule Core i5 ~18 min
 ~40 min

    ~10 min
 ~11 min Core i7 13 min
 ~30 min 8 min
 ~8 min + no need to recompile whole project when -Owholemodule used
  8. Frameworks pitfalls Done post-factum Code had to be decoupled Class

    scope properly annotated Missing imports added Problems with Xcode
  9. Frameworks benefits Much faster compilation times Less coupled code Frameworks

    could be separately tested No need to recompile frameworks each time
  10. Migrations Swift 1.2 Swift 2.1 Swift 2.2 2 days 2

    attempts (3 weeks totally) author: Christophe Boisson
  11. The migration process Auto migration Manual fixes Code Review ~9

    hrs Unplanned tasks compiler bug workarounds
  12. Migrations pitfalls Migration tool is solving only a % of

    your problems swiftc in Xcode 7.2 was crashing when
 compiling our project Lots of warnings generated (2.1 -> 2.2) Need for manual review of auto migrated code
 (i.e. force unwrap)
  13. Mixes of old and new Swift patterns Fix all warnings

    ASAP otherwise they
 will be out of your control All developers has to migrate at once Hard to back port code Migrations pitfalls (II)
  14. Why so many files? Auto generated Service Layer Single responsibility

    principle Protocols in independent files Extensions
  15. Reported problem to Apple (SR-280) Fixed in Xcode 7.3 Provided

    a workaround for 7.2 The +1500 Swift files problem (Xcode 7.2) swiftc wrapper swiftc -num-threads 0 with fork instead of posix_spawn Xcode More info: https://github.com/tgebarowski/swiftc-wrapper
  16. Xcode - we have a problem! Refactoring not supported lldb

    not working in - Owholemodule Symbols not indexed properly when inside frameworks 1 2 3 4
  17. GO Successfully deployed rewritten app Developers are more enthusiastic about

    Swift We observed less crashes after deploying Swift version of app Less runtime errors 23% less lines of code