Implementing iOS Collection View with Efficient Rendering Mechanism
Article Summary
Tokopedia's iOS team was crashing on UICollectionView batch updates. Their solution? Build a better abstraction inspired by Instagram and SwiftUI.
The engineering team at Tokopedia faced performance issues with dynamic layouts using UICollectionView's performBatchUpdates. Wrong indexPaths caused crashes, and reloadData was too slow for complex UIs with hundreds of cells.
Key Takeaways
- Switched from UICollectionView to Texture's ASCollectionNode for background thread rendering
- Built ListNode: a wrapper that automates diffing and eliminates manual indexPath management
- Diffing algorithm calculates inserts, deletes, updates, and moves automatically
- API inspired by IGListKit and SwiftUI List for easier future migration
- Prevents NSInternalInconsistencyException crashes from incorrect batch updates
Critical Insight
ListNode abstracts away the complexity of performBatchUpdates by automatically calculating cell changes through diffing, making ASCollectionNode as simple to use as SwiftUI's List.