Getting to Swift 3

By Chengyin Liu, Paul Kompfner, and Michael Bachand

Chengyin Liu
13 min readadvanced
--
View Original

Overview

The article discusses Airbnb's migration from Swift 2 to Swift 3, detailing the challenges faced and the strategies employed to ensure a smooth transition without halting development. It highlights the impact of Swift 3 on the codebase, including changes in IPA size and build times, and shares insights on the code conversion process and common pitfalls encountered.

What You'll Learn

1

How to create a dependency graph for code migration

2

Why incremental conversion is crucial during language migration

3

How to monitor the impact of Swift 3 on build metrics

4

When to apply manual fixes after using the Xcode conversion tool

Prerequisites & Requirements

  • Understanding of Swift programming language
  • Familiarity with Xcode and CocoaPods(optional)

Key Questions Answered

What challenges did Airbnb face during the migration to Swift 3?
Airbnb faced significant challenges including the incompatibility between Swift 2 and Swift 3 modules, which prevented them from importing each other. This made it difficult to parallelize the migration process, necessitating a carefully planned incremental conversion strategy.
What was the impact of Swift 3 on the release IPA size?
After migrating to Swift 3, Airbnb observed a 2.2MB increase in their release IPA size, primarily due to the increased size of Swift's libraries. For example, libswiftFoundation.dylib increased by 233.40%, highlighting the trade-off between new features and application size.
How did the migration affect debug build times?
The migration to Swift 3 resulted in a 4.6% increase in debug build time, adding 16 seconds to the previous 6-minute duration. This change emphasized the need for careful profiling and optimization during the conversion process.
What steps were taken to ensure no disruption to development during migration?
Airbnb avoided a code freeze by employing a three-person team to work on the migration incrementally. They created a dependency graph to manage module upgrades and maintained ongoing development to continue shipping new releases.

Key Statistics & Figures

Release IPA Size Increase
2.2MB
This increase was mainly due to the larger size of Swift's libraries post-migration.
Debug Build Time Increase
4.6%
This translated to an additional 16 seconds on a previous 6-minute build time.
libswiftFoundation.dylib Size Increase
233.40%
This significant increase contributed to the overall rise in release IPA size.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Programming Language
Swift
Used for developing Airbnb's mobile application.
Development Environment
Xcode
Utilized for code conversion and development during the migration process.
Dependency Manager
Cocoapods
Upgraded to support necessary pod upgrades during the migration.

Key Actionable Insights

1
Create a dependency graph to manage module upgrades effectively during migrations.
This approach allows teams to visualize dependencies and prioritize the conversion of modules, minimizing disruption and ensuring a smoother transition.
2
Monitor build metrics closely after migration to identify potential performance regressions.
By tracking metrics like IPA size and build times, teams can assess the impact of language changes and make necessary adjustments to optimize performance.
3
Utilize tools like Build Time Analyzer for Xcode to identify and resolve compile time issues.
This tool helps pinpoint functions that may cause slowdowns, allowing developers to focus their optimization efforts where they are most needed.

Common Pitfalls

1
Overlooking runtime behavior changes post-migration can lead to regressions.
The Xcode conversion tool does not guarantee identical runtime behavior, necessitating thorough testing and QA cycles to catch potential issues.
2
Failing to update optional protocol method implementations can result in silent failures.
Optional protocol methods may compile without errors even if their signatures are outdated, leading to unexpected behavior at runtime.

Related Concepts

Swift Programming Language
Code Migration Strategies
Performance Optimization Techniques