Instagram open sources iOS UI crash fix
App devs: if UICollectionView bugs you, this might help
Instagram's latest open source drop is its answer to a difficult iOS bug – a UI component crashing when users scroll through updates.
At the same time, its offering should shrink apps for developers trying to push updates to users, with faster diff (difference) processing.
Explaining its IGListKit project, Instagram engineer Ryan Nystrom explains the outfit was bumping into two issues in pushing server data into different UI lists: its view controller was getting too fat, and there was “too much inheritance”.
“Making a single change in one object sometimes required making changes in everything it was inherited from.”
To push changes at the server all the way out to users' apps, Instagram used Apple's UICollectionView, which Cupertino first made part of iOS in version 6.0 (and since added to Swift and Xcode).
However, Nystrom writes, running lots of updates through UICollectionView can be a pain: “new data arrives from the server each time you like a photo or you receive a direct message in real-time UICollectionView can handle all types of updates (deletes, reloads, moves, and inserts), but performing those updates without crashing can be a little tricky.”
(There's plenty of “why is UICollectionView questions on StackExchange, so devs will apparently agree.)
Simple architecture for pushing status updates in IGListKit
To create IGListKit, Instagram's combined the UICollectionView architecture with an implementation of Paul Heckel's venerable but popular diffing algorithm.
(Aside: Heckel's algorithm may date back to 1978 – you can read his paper here – but it's still popular enough to turn up in lots of GitHub projects.)
The point of the Heckel diff algorithm is that it can find all the diffs a developer needs to push to the user interface in linear time – which is why Instagram reckons it's better than handling the diffs in UICollectionView.
IGListKit is currently supported in CocoaPods and Xcode. ®
Sponsored: Beyond the Data Frontier