Slide 1

Slide 1 text

Swift at scale @tgebarowski (revised) Tomasz Gebarowski Unconference 17.05.2017

Slide 2

Slide 2 text

mobile banking app @tgebarowski

Slide 3

Slide 3 text

@tgebarowski

Slide 4

Slide 4 text

some stats +10 developers 2 years of development +3200 Swift files 100’s of View Controllers, Cells We use code generation 3 migrations between Swift versions @tgebarowski

Slide 5

Slide 5 text

scale effect compilation times migrations @tgebarowski

Slide 6

Slide 6 text

@tgebarowski compilation times https://xkcd.com/303/

Slide 7

Slide 7 text

1 minute? @tgebarowski

Slide 8

Slide 8 text

5 minutes? @tgebarowski

Slide 9

Slide 9 text

up to 40 minutes… @tgebarowski

Slide 10

Slide 10 text

https://github.com/riamf/XcodeBuildTimeMeasurement Day time (s) formatted time no builds 10.10.2016 7297 2h 1m 37s 24 11.10.2016 12221 3h 23m 41s 87 12.10.2016 7146 1h 59m 5s 79 13.10.2016 8885 2h 28m 5s 107 14.10.2016 4452 1h 14m 12s 33 @tgebarowski

Slide 11

Slide 11 text

Compilation times -Onone -whole-module- optimization Core i5 ~40 min ~11 min Core i7 ~30 min ~8 min @tgebarowski

Slide 12

Slide 12 text

Why -Onone is so slow? In a large project, single Swift file compilation takes ~1 second

Slide 13

Slide 13 text

Why -Onone is so slow? -filelist argument contains a list of all Swift files in a project

Slide 14

Slide 14 text

specialisation of generic functions for concrete types inlining dead function/method elimination source: swift.org @tgebarowski whole-module optimization

Slide 15

Slide 15 text

single invocation of frontend with -filelist argument @tgebarowski whole-module optimization

Slide 16

Slide 16 text

could it be faster? @tgebarowski

Slide 17

Slide 17 text

compilation times -Onone -whole-module- optimization SWIFT_WHOLE_MODULE_ OPTIMIZATION=YES Core i5 ~40 min ~11 min ~5 min Core i7 ~30 min ~8 min ~3 min @tgebarowski

Slide 18

Slide 18 text

swift -frontend -primary-file file1.swift -filelist file swift -whole-module-optimization file1.swift file2.swift file3.swift how it works? swift -Onone file1.swift file2.swift file3.swift swift -frontend -whole-module-optimization -filelist file swift -frontend -primary-file file2.swift -filelist file swift -frontend -primary-file file3.swift -filelist file spawn spawn spawn spawn -whole-module-optimization -Onone @tgebarowski

Slide 19

Slide 19 text

swift -whole-module-optimization file1.swift file2.swift file3.swift the trick swift -frontend -whole-module-optimization -Onone -filelist file spawn SWIFT_WHOLE_MODULE_OPTIMIZATION=YES @tgebarowski

Slide 20

Slide 20 text

@tgebarowski beware of large targets! 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

Slide 21

Slide 21 text

Frameworks! One Monolithic Mobile App MBFoundation MBServiceKit MBUtilityKit MBCoreKit MBGlueKit MobileApp dropping iOS 7 support @tgebarowski

Slide 22

Slide 22 text

-Onone -Owholemodule Core i5 ~18 min
 ~40 min ~10 min
 ~11 min Core i7 13 min
 ~30 min 8 min
 ~8 min compilation times after introducing frameworks @tgebarowski

Slide 23

Slide 23 text

Migrations Swift 1.2 Swift 2.1 Swift 2.2 2 days ~3 weeks author: Christophe Boisson Swift 3 7 days @tgebarowski

Slide 24

Slide 24 text

Swift 1.2 Swift 2.1 ~3 weeks Swift 2.2 Swift 3 7 days 8h Migration Tool 2 days Manual Fixes 2 devs 5 days Bypassing 
 compiler bug 3h Migration Tool 4 days Manual Fixes 3 devs ~3800 errors ~1600 errors 5 days Regression testing 2 days Regression testing

Slide 25

Slide 25 text

migration process Auto migration Code Freeze Migrating Core frameworks Migrating App itself Migrating Unit and UI tests Regression and fixing issues Auto migration Migrating Core frameworks Estimating number and types of bugs to fix migration evaluation migration process @tgebarowski

Slide 26

Slide 26 text

@tgebarowski Swift 3 Migration Issues • dequeueReusableCellWithIdentifier -> dequeueReusableCell(withIdentifier:for:) • hidden -> isHidden • enabled -> isEnabled • popViewControllerAnimated -> popViewController(animated:) • registerNib(_:forCellReuseIdentifier:) -> register(_:forCellReuseIdentifier:) • wszystkie błędy związane z rename’ing enumów ‚X’ has been renamed to ‚Y’ 551 errors extraneous argument label 250 errors explicitly marked unavailable here 570 errors has no case „X”, did you mean „x” 523 errors NSDate & Date related 114 errors

Slide 27

Slide 27 text

The +1500 Swift files problem (Xcode 7.2) swiftc crash @tgebarowski Migration Issues

Slide 28

Slide 28 text

swift -frontend swiftc swift -frontend posix_spawn swift -frontend … crash The +1500 Swift files problem (Xcode 7.2) @tgebarowski

Slide 29

Slide 29 text

@tgebarowski Reported problem to Apple (SR-280) Fixed in Xcode 7.3 Provided a workaround for 7.2 swiftc wrapper swiftc -num-threads 0 with fork instead of posix_spawn Xcode More info: https://github.com/tgebarowski/swiftc-wrapper The +1500 Swift files problem (Xcode 7.2)

Slide 30

Slide 30 text

Thank You! @tgebarowski

Slide 31

Slide 31 text

@tgebarowski Swift at scale Tomasz Gebarowski