LinkedIn has one of the largest iOS products available - in terms of customers and complexity. In this talk I share our war stories as we worked on a large codebase across multiple apps and multiple libraries... all in Swift.
The talk structure starts with giving context of how vast our use of Swift is at LinkedIn, then delves into some of the issues we've run into because of our scale, how we've solved those, and ends with a summary of our general approach to fixing these issues. Most of the issues relate to Xcode's Swift compiler, build time, and Swift migrations.
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Swift at Scale
1. SWIFT AT SCALE
WAR STORIES FROM
KAMILAH TAYLOR, SENIOR SOFTWARE ENGINEER, LINKEDIN
#SwiftSummit 2016 @kamilah
2. I SINCERELY PROMISE TO
KEEP MY SWIFT 3 MIGRATION
COMPLAINTS TO A MINIMUM.
@kamilah
SO THIS TALK... #SwiftSummit
3. REALLY I PROMISE EVEN THOUGH THIS IS HOW I DREAM OF XCODE NOW
@kamilah #SwiftSummit
4. SWIFT AT LINKEDIN
WHAT I MEAN WHEN I SAY AT SCALE
▸ In January 2015, we started the
complete rewrite of our flagship
app in Swift, as part of project
Voyager
▸ It's not just one app, it's a growing
family of apps
▸ It's not just a family of apps, it's a
growing set of libraries, internally
and open sourced
▸ ~100 iOS devs, ~40 on flagship
@kamilah #SwiftSummit
5. SWIFT AT LINKEDIN
THE WORKFLOW
▸ Weekly release cycles
▸ Large unit and integration test suites
▸ First version of Swift embraced - the betas (https://
engineering.linkedin.com/ios/our-swift-experience-
slideshare)
▸ Number of Swift files in our flagship app - over 4500
@kamilah #SwiftSummit
6. HOW DO WE HAVE
IT ALL?
SPOILER ALERT: WE DON'T.
THIS IS HARD. HERE ARE
SOME STORIES.
@kamilah #SwiftSummit
8. THE COMPILE TIME STORIES
DEVELOPER HAPPINESS + PRODUCTIVITY
▸ Compile times very very very long for large codebase (~25
min for a cold build on 15” rMBP)
▸ This has improved with each Xcode version
▸ Three workarounds
▸ code structure
▸ hardware
▸ objective-c (yes, really)
@kamilah #SwiftSummit
9. THE COMPILE TIME STORIES
THE SOLUTION FOR VOYAGER
▸ Mac Pros for everyone! (12 cores gave us a 2x speed boost over the top
of the line MBP)
▸ Switched generated models to ObjC (to reduce the number of Swift files)
▸ Code structure
▸ Dropped iOS 7 support
▸ Modularized using Cocoapod's devpods
▸ This broke debug symbols
▸ Converted devpods into dynamic frameworks
@kamilah #SwiftSummit
10. @kamilah
THE XCODE PROJECT FILE
FIELD NOTE NUMBER 12:
SOMETIMES YOU MAY NEED
DARK MAGIC TO EDIT THE
PROJECT FILE
#SwiftSummit
11. THE XCODE PROJECT FILE
DARK MAGIC IS NOT AN EXAGGERATION
@kamilah #SwiftSummit
12. THAT SEGFAULT 11 THOUGH
http://classicprogrammerpaintings.com/post/142796894989/c-
developers-aiding-a-comrade-facing-segfault
@kamilah #SwiftSummit
13. THAT SEGFAULT 11 THOUGH
SOMETIMES THE XCODE COMPILER JUST CRASHES
▸ The problem (on LinkedIn Learning): Our builds started to
flakily fail because of a compiler crash once we added a
full test suite, as we geared up for our launch
▸ Even locally, the compiler would occasionally crash with a
segfault 11
▸ The solution: Back to manipulating the xcode project
settings, a skill I don't remember needing in the objective-
c days
@kamilah #SwiftSummit
14. THE BUILD ALWAYS NEEDS WORK
FAILED TO AUTHORIZE RIGHTS (0X1) WITH STATUS: -60007
▸ The problem: Our builds started to flakily fail because of a
compiler crash (Xcode 7.3) - for everyone's app
▸ Really bad side effect - missing when an actual bad
commit went in while the trunk is red
▸ The solution: Our tools team found a work around by
splitting the test build (done in xcodebuild) and running
tests, now via xctool
▸ Funny follow up: had to revert this patch for Swift 3
@kamilah #SwiftSummit
16. SWIFT BETA - SWIFT 2
THE EARLY DAYS OF MIGRATING
▸ Pre Swift 2
▸ This mostly affected Slideshare, our first Swift app
▸ No migrator tool so all manual
@kamilah #SwiftSummit
17. SWIFT BETA - SWIFT 2
THE EARLY DAYS OF MIGRATING
▸ Swift 2 migration
▸ Needed Xcode 7 for the improved build times
▸ 2 months before launch
▸ Migration tool crashed on large codebase (okay for
smaller apps at LinkedIn)
▸ (What we thought was) Lengthy, manual migration to
new Swift version for Voyager
@kamilah #SwiftSummit
18. BEYOND SWIFT 2
AND THEN 2016 CAME...WITH SWIFT 2.3 AND SWIFT 3
@kamilah #SwiftSummit
19. SWIFT 2 - SWIFT 2.3
IT WAS ONLY KIND OF A PAIN FREE MIGRATION
▸ Swift 2.3
▸ Again, we needed to upgrade to Xcode 8
▸ Actually quite painful for Voyager
▸ 14 Swift libraries, 4500 Swift files in Voyager
▸ For LinkedIn Learning, actually not so bad
▸ Took me about 1 week since libraries had already
been migrated and migrator "worked"
@kamilah #SwiftSummit
20. THAT INITIAL ERROR COUNT OF
666 WAS THE FIRST SIGN.
@kamilah
MIGRATING TO SWIFT 3 #SwiftSummit
21. SWIFT 3
QUITE POSSIBLY THE WORST DEVELOPER EXPERIENCE
▸ The migrator tool, pretty much useless
▸ Saving grace: http://swift.ayaka.me/posts/2016/6/17/
running-the-swift-30-migrator-on-a-standalone-swift-file
▸ Had a script that ran this for an entire directory
▸ The battle had only begun
▸ Massive effort to upgrade all the swift libraries from the
infra and voyager team
@kamilah #SwiftSummit
23. THE SWIFT 3 MIGRATION
THESE ARE ACTUAL COMMIT MESSAGES FROM THE VOYAGER TEAM
@kamilah #SwiftSummit
24. SWIFT 3
QUITE POSSIBLY THE WORST DEVELOPER EXPERIENCE
▸ Voyager
▸ Froze the trunk for nearly two weeks
▸ LinkedIn Learning
▸ Still ongoing, even on our much smaller codebase (~800
Swift files) the migrator crashed
@kamilah #SwiftSummit
25. THE SWIFT 3 MIGRATION
OKAY A FEW MORE COMMIT MESSAGES
@kamilah #SwiftSummit
26. SO HOW DO WE DO SWIFT
AT SCALE AT LINKEDIN?
@kamilah #SwiftSummit
27. ALMOST DONE...
SO HOW HAVE WE DONE SWIFT AT SCALE AT LINKEDIN?
▸ Early adoption -> hard earned learnings both from our
developers and tools team
▸ Communicate communicate communicate
▸ Frequent knowledge sharing across the company
▸ Internal iOS meetups
▸ Many slack channels, including a dedicated one for swift 3
▸ Open sourced a swift style guide
@kamilah #SwiftSummit
28. ALMOST DONE...
SO HOW HAVE WE DONE SWIFT AT SCALE AT LINKEDIN?
▸ Constant experimentation on how to improve our build
and compile times
▸ Shout out to our tools team who are always trying to
improve the process, test new versions of Xcode
@kamilah #SwiftSummit
29. NOW I'M DONE
LEARNINGS
▸ This won't come for free
▸ Invest in your tools and infra teams
▸ Swift does require more developer time for maintenance,
though less time for training and actual coding
▸ Be ready with much patience and all the humor
@kamilah #SwiftSummit