From 86ecc600856b4199f8a31359140753955f02b5a4 Mon Sep 17 00:00:00 2001 From: Maxime Ollivier Date: Fri, 26 Jun 2020 10:03:47 -0700 Subject: [PATCH] clean up IGListExperimentReloadDataFallback Summary: This experiment shipped so we can remove it. We still need a way to disable it with `allowsReloadingOnTooManyUpdates` in case we don't want to resign the first responder on large updates. Reviewed By: Haud Differential Revision: D22219238 fbshipit-source-id: 98e78f3ed040809db6c4b4c8da8fd0e976aca0a2 --- CHANGELOG.md | 2 ++ Source/IGListDiffKit/IGListExperiments.h | 4 +--- Source/IGListKit/IGListAdapterUpdater.h | 6 ++++++ Source/IGListKit/IGListAdapterUpdater.m | 4 +++- Tests/IGListAdapterE2ETests.m | 2 -- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25419320d..869de515d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag - Improved performance by deferring requesting objects from the `IGListAdapterDataSource` until just before diffing is executed. If n updates are coalesced into one, this results in just a single request for objects from the data source. Shipped with experiment `IGListExperimentDeferredToObjectCreation` from Ryan Nystrom. [Maxime Ollivier](https://github.com/maxolls) (tbd) +- Improved performance by using `reloadData` when there are too many diffing updates. Shipped with experiment `IGListExperimentReloadDataFallback` from Ryan Nystrom. [Maxime Ollivier](https://github.com/maxolls) (tbd) + ### Fixes - `IGListCollectionViewLayout` should get the section/index counts via `UICollectionView` to stay in sync, instead of the `dataSource` [Maxime Ollivier](https://github.com/maxolls) (tbd) diff --git a/Source/IGListDiffKit/IGListExperiments.h b/Source/IGListDiffKit/IGListExperiments.h index 293e8b22d..1f3c0f2c7 100644 --- a/Source/IGListDiffKit/IGListExperiments.h +++ b/Source/IGListDiffKit/IGListExperiments.h @@ -18,10 +18,8 @@ typedef NS_OPTIONS (NSInteger, IGListExperiment) { IGListExperimentNone = 1 << 1, /// Test updater diffing performed on a background queue. IGListExperimentBackgroundDiffing = 1 << 2, - /// Test fallback to reloadData when "too many" update operations. - IGListExperimentReloadDataFallback = 1 << 3, /// Test invalidating layout when cell reloads/updates in IGListBindingSectionController. - IGListExperimentInvalidateLayoutForUpdates = 1 << 4, + IGListExperimentInvalidateLayoutForUpdates = 1 << 3, }; /** diff --git a/Source/IGListKit/IGListAdapterUpdater.h b/Source/IGListKit/IGListAdapterUpdater.h index 71b745071..c7895fa12 100644 --- a/Source/IGListKit/IGListAdapterUpdater.h +++ b/Source/IGListKit/IGListAdapterUpdater.h @@ -68,6 +68,12 @@ NS_SWIFT_NAME(ListAdapterUpdater) */ @property (nonatomic, assign) BOOL allowsBackgroundReloading; +/** + If there's more than 100 diff updates, fallback to using `reloadData` to avoid stalling the main thread. + Default is YES. + */ +@property (nonatomic, assign) BOOL allowsReloadingOnTooManyUpdates; + /** A bitmask of experiments to conduct on the updater. */ diff --git a/Source/IGListKit/IGListAdapterUpdater.m b/Source/IGListKit/IGListAdapterUpdater.m index 721f5a14a..29f333d68 100644 --- a/Source/IGListKit/IGListAdapterUpdater.m +++ b/Source/IGListKit/IGListAdapterUpdater.m @@ -28,6 +28,7 @@ - (instancetype)init { _completionBlocks = [NSMutableArray new]; _batchUpdates = [IGListBatchUpdates new]; _allowsBackgroundReloading = YES; + _allowsReloadingOnTooManyUpdates = YES; } return self; } @@ -110,6 +111,7 @@ - (void)performBatchUpdatesWithCollectionViewBlock:(IGListCollectionViewBlock)co NSMutableArray *completionBlocks = [self.completionBlocks mutableCopy]; void (^objectTransitionBlock)(NSArray *) = [self.objectTransitionBlock copy]; const BOOL animated = self.queuedUpdateIsAnimated; + const BOOL allowsReloadingOnTooManyUpdates = self.allowsReloadingOnTooManyUpdates; IGListBatchUpdates *batchUpdates = self.batchUpdates; // clean up all state so that new updates can be coalesced while the current update is in flight @@ -284,7 +286,7 @@ - (void)performBatchUpdatesWithCollectionViewBlock:(IGListCollectionViewBlock)co if (collectionView.dataSource == nil) { // If the data source is nil, we should not call any collection view update. fallbackWithoutUpdates(); - } else if (result.changeCount > 100 && IGListExperimentEnabled(experiments, IGListExperimentReloadDataFallback)) { + } else if (result.changeCount > 100 && allowsReloadingOnTooManyUpdates) { reloadDataFallback(); } else { performUpdate(result); diff --git a/Tests/IGListAdapterE2ETests.m b/Tests/IGListAdapterE2ETests.m index d98a5ae7f..dec957597 100644 --- a/Tests/IGListAdapterE2ETests.m +++ b/Tests/IGListAdapterE2ETests.m @@ -1533,8 +1533,6 @@ - (void)test_whenMassiveUpdate_thatUpdateApplied { // init empty [self setupWithObjects:@[]]; - ((IGListAdapterUpdater *)self.updater).experiments = IGListExperimentReloadDataFallback; - NSMutableArray *objects = [NSMutableArray new]; for (NSInteger i = 0; i < 3000; i++) { [objects addObject:genTestObject(@(i + 1), @4)];