In 2012 Facebook relaunched their iOS app to use native code. This was a big shift in architecting and implementing the Facebook app experience, the most widely used third party app on the entire iOS platform. Adam Ernst will speak about how the decision was made to switch to native code and how the company prepared to rewrite the app. He will share an inside look at the APIs and technical architecture Facebook uses to enable dozens of iOS developers to work on the same application. Automated testing is very important to Facebook, so Adam will also speak about how Facebook uses testing on iOS to keep the app reliable.
4. Agenda
▪ “Over the wall”: some history
▪ Product Teams and the Core Team
▪ Scheduling and Stabilizing Releases
▪ How We Develop
▪ Eating the Dogfood: Builds
▪ A Culture of Unit Testing
▪ Future of iOS at Facebook
6. Facebook for Mobile
▪ Web deeply engrained in Facebook’s DNA
▪ Use HTML5/Javascript within “wrapper” native app
▪ Developed our own framework for advanced integration
(image uploads, photo browsers, mixing native/web elements)
7. HTML as an app platform
▪ What does it bring us?
One CodebaseInstant Updates A/B Testing
9. A few engineers in a room
▪ Facebook for iOS 5.0 began as an experiment
10. A few engineers in a room
▪ Facebook for iOS 5.0 began as an experiment
▪ Could we achieve better results with native code?
11. A few engineers in a room
▪ Facebook for iOS 5.0 began as an experiment
▪ Could we achieve better results with native code?
▪ High barrier: requires rewriting every part of Facebook’s mobile UI!
12. A few engineers in a room
▪ Facebook for iOS 5.0 began as an experiment
▪ Could we achieve better results with native code?
▪ High barrier: requires rewriting every part of Facebook’s mobile UI!
▪ Couldn’t disrupt company for something that might not ship
(At the time, few iOS engineers at Facebook anyway)
13. A few engineers in a room
▪ Facebook for iOS 5.0 began as an experiment
▪ Could we achieve better results with native code?
▪ High barrier: requires rewriting every part of Facebook’s mobile UI!
▪ Couldn’t disrupt company for something that might not ship
(At the time, few iOS engineers at Facebook anyway)
▪ Sequester some engineers in a war room, and have them
write the product from top to bottom
14. Reaction
▪ Press loved it
▪ More importantly…
▪ Perceived Speed way up
▪ User Ratings way up
▪ 2x Speed increase!
15. Reaction
▪ Press loved it
▪ More importantly…
▪ Perceived Speed way up
▪ User Ratings way up
▪ 2x Speed increase!
23. Fixed Release Cycle
▪ Waiting for all features in a
release to be “done” slowed us
down, and we want to move fast
▪ So, ship an update every X weeks
▪ … no matter what
▪ Popularized by Mozilla
24. Building features with an “off switch”
▪ Every feature must be built with a way to
turn it off
▪ If a feature destabilizes the build or isn’t
complete, turn it off and try again next
time
▪ #defines – or runtime switches
(preferred)
37. Check code
▪ ‘arc lint’
▪ Set up rules to catch common mistakes
▪ Examples:
▪ Enforce style guidelines
▪ Warn against using certain symbols
▪ Check for common pattern mistakes, and fix them!
42. AST Lint Rules
▪ Regular expressions have false positives and negatives
▪ Dot notation vs braces
▪ Even mentioning forbidden API in a comment triggers rule!
▪ AST lint rules can “understand the code”
43. Verify changes: Buildbot
▪ Continuous integration
▪ Distributed across multiple build machines
▪ Sanity check:
▪ Do all projects still build?
▪ Do all unit tests still pass?
▪ Emails engineer, and updates Phabricator on failure
47. Multiple Builds
▪ Use different bundle IDs and icons for different types of builds:
▪ Development
▪ Daily Build
▪ App Store release
▪ Special branches
▪ Burn your build number into your icon
48.
49. Branching
▪ Two concurrent branches:
▪ Master
▪ Engineers make progress on future features
▪ All changes checked in here first
▪ …including bug fixes for Releases
▪ Release
▪ Once verified in Master…
▪ …“Release team” pulls them into Release branch
51. Testing is important to Facebook
▪ Not in Facebook’s culture:
▪ SDEs “in Test”
▪ Large QA departments
▪ Definitely in Facebook culture:
▪ High quality, reliable user experience
▪ We believe in developer-authored unit tests
55. Watchdog Timer
Main Thread work work work work workwork
Watchdog
Thread
ping
ack
ping
ack
ping
ack
ping
ack
ping
ack
ping
Uh oh! No ack.
Log backtrace.
56. Watchdog Timer: How it Works
▪ Max-priority thread pings main thread every X seconds
▪ If main thread doesn’t respond in time…
▪ Freeze the main thread
▪ Get the backtrace to see what code is running
▪ Log it to our servers for analysis
github.com/facebook/ios-watchdog-timer
NEW
57. Rage Shake
▪ Shake the device to report a bug
▪ Captures:
▪ Screen shot (with annotations!)
▪ Network logs
▪ Last crash log
▪ Last x-seconds of logging
▪ Dumps the view hierarchy
▪ Automatically files a bug and sends it to Facebook