From 9fcc122ed0bac290ef9215663ec37b8f1d909fae Mon Sep 17 00:00:00 2001 From: Zhisheng Huang Date: Wed, 8 Apr 2020 11:44:47 -0700 Subject: [PATCH] Improve scroll perf on single section inline update QE Summary: = Context = Thanks to the awesome Comparison View analysis, I am able to pinpoint where the scroll perf regression is for the single section inline update QE. CV2 link: https://fburl.com/cv/fttkv99b Also see from the graph that the these call stacks are pretty stat-sig, https://pxl.cl/14D9M And from the following stack stats, it's pretty clear that the heaviest one is calling from `-[IGListBindingSingleSectionController didUpdateToObject:]`, Approx. Frame Percentage is 24% to 1% compared to Control test group for my QE. https://pxl.cl/14Db0 = Root cause = Basically in my new QE, whenever IGListKit update, the -didUpdateToObject: is called on every single IGListSectionController, which in our case, we would call -[-configureCell:withViewModel:] all every single cells. And it's actually pretty expensive for any cell configuration: https://pxl.cl/14DbZ In control group, we never trigger any cell "Re-binding" thus no heavy impact. However the way control group works is, that we always trigger another cell creation and replace with the existing one. IGListKit would still check -isEqualToDiffable: to decide whether the current cell needs a reload, the logic is inside IGListAdapterUpdater. = Solution = It's easy, just do a simple `-isEqualtoDiffable:` check before updating the _item, inside `[-IGListBindingSingleSectionController didUpdateToObject:]` method. Differential Revision: D20909174 fbshipit-source-id: 59d57fc8ddda7210cd1ae333942a345025cf1ee3 --- Source/IGListKit/IGListBindingSingleSectionController.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/IGListKit/IGListBindingSingleSectionController.m b/Source/IGListKit/IGListBindingSingleSectionController.m index 405f8486..3e1e8fed 100644 --- a/Source/IGListKit/IGListBindingSingleSectionController.m +++ b/Source/IGListKit/IGListBindingSingleSectionController.m @@ -15,7 +15,7 @@ @end @implementation IGListBindingSingleSectionController { - id _item; + id _item; __weak UICollectionViewCell *_displayingCell; } @@ -68,7 +68,10 @@ return cell; } -- (void)didUpdateToObject:(id)object { +- (void)didUpdateToObject:(id)object { + if ([_item isEqualToDiffableObject:object]) { + return; + } _item = object; if (_enabledCellConfigurationDuringUpdate) {