diff --git a/CHANGELOG.md b/CHANGELOG.md index d7733700e..52b46e387 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag - Removed `allowsBackgroundReloading` from `IGListAdapterUpdater` because it's causing performance issues and other bugs. [Maxime Ollivier](https://github.com/maxolls) (tbd) +- Introducing `allowsBackgroundDiffing` on `IGListAdapterUpdater`! This property lets the updater perform the diffing on a background thread. Originally introduced by Ryan Nystrom a while back. [Maxime Ollivier](https://github.com/maxolls) (tbd) + ### Enhancements - Added `shouldSelectItemAtIndex:` to `IGListSectionController` . [dirtmelon](https://github.com/dirtmelon) diff --git a/Source/IGListDiffKit/IGListExperiments.h b/Source/IGListDiffKit/IGListExperiments.h index 7d4078a62..f0446f7d5 100644 --- a/Source/IGListDiffKit/IGListExperiments.h +++ b/Source/IGListDiffKit/IGListExperiments.h @@ -16,14 +16,12 @@ NS_SWIFT_NAME(ListExperiment) typedef NS_OPTIONS (NSInteger, IGListExperiment) { /// Specifies no experiments. IGListExperimentNone = 1 << 1, - /// Test updater diffing performed on a background queue. - IGListExperimentBackgroundDiffing = 1 << 2, /// Test invalidating layout when cell reloads/updates in IGListBindingSectionController. - IGListExperimentInvalidateLayoutForUpdates = 1 << 3, + IGListExperimentInvalidateLayoutForUpdates = 1 << 2, /// Test skipping performBatchUpdate if we don't have any updates. - IGListExperimentSkipPerformUpdateIfPossible = 1 << 4, + IGListExperimentSkipPerformUpdateIfPossible = 1 << 3, /// Test skipping creating {view : section controller} map, which has inconsistency issue. - IGListExperimentSkipViewSectionControllerMap = 1 << 5 + IGListExperimentSkipViewSectionControllerMap = 1 << 4 }; /** diff --git a/Source/IGListKit/IGListAdapterUpdater.h b/Source/IGListKit/IGListAdapterUpdater.h index ae80538e2..924fd1ede 100644 --- a/Source/IGListKit/IGListAdapterUpdater.h +++ b/Source/IGListKit/IGListAdapterUpdater.h @@ -69,6 +69,13 @@ NS_SWIFT_NAME(ListAdapterUpdater) */ @property (nonatomic, assign) BOOL allowsReloadingOnTooManyUpdates; +/** + Allow the diffing to be performed on a background thread. + + Default is NO. + */ +@property (nonatomic, assign) BOOL allowsBackgroundDiffing; + /** A bitmask of experiments to conduct on the updater. */ diff --git a/Source/IGListKit/IGListAdapterUpdater.m b/Source/IGListKit/IGListAdapterUpdater.m index fe140d7b8..03036ff05 100644 --- a/Source/IGListKit/IGListAdapterUpdater.m +++ b/Source/IGListKit/IGListAdapterUpdater.m @@ -90,6 +90,7 @@ - (void)update { .singleItemSectionUpdates = _singleItemSectionUpdates, .preferItemReloadsForSectionReloads = _preferItemReloadsForSectionReloads, .allowsReloadingOnTooManyUpdates = _allowsReloadingOnTooManyUpdates, + .allowsBackgroundDiffing = _allowsBackgroundDiffing, .experiments = _experiments, }; diff --git a/Source/IGListKit/Internal/IGListAdapterUpdater+DebugDescription.m b/Source/IGListKit/Internal/IGListAdapterUpdater+DebugDescription.m index 3c8b1f449..18871d302 100644 --- a/Source/IGListKit/Internal/IGListAdapterUpdater+DebugDescription.m +++ b/Source/IGListKit/Internal/IGListAdapterUpdater+DebugDescription.m @@ -22,7 +22,8 @@ @implementation IGListAdapterUpdater (DebugDescription) [NSString stringWithFormat:@"sectionMovesAsDeletesInserts: %@", IGListDebugBOOL(self.sectionMovesAsDeletesInserts)], [NSString stringWithFormat:@"singleItemSectionUpdates: %@", IGListDebugBOOL(self.singleItemSectionUpdates)], [NSString stringWithFormat:@"preferItemReloadsForSectionReloads: %@", IGListDebugBOOL(self.preferItemReloadsForSectionReloads)], - [NSString stringWithFormat:@"allowsReloadingOnTooManyUpdates: %@", IGListDebugBOOL(self.allowsReloadingOnTooManyUpdates)] + [NSString stringWithFormat:@"allowsReloadingOnTooManyUpdates: %@", IGListDebugBOOL(self.allowsReloadingOnTooManyUpdates)], + [NSString stringWithFormat:@"allowsBackgroundDiffing: %@", IGListDebugBOOL(self.allowsBackgroundDiffing)] ]; [debug addObjectsFromArray:IGListDebugIndentedLines(options)]; diff --git a/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m b/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m index 927e10dc1..7c5611e56 100644 --- a/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m +++ b/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m @@ -102,7 +102,7 @@ - (void)_diff { IGListTransitionData *data = self.sectionData; [self.delegate listAdapterUpdater:self.updater willDiffFromObjects:data.fromObjects toObjects:data.toObjects]; - const BOOL onBackground = IGListExperimentEnabled(self.config.experiments, IGListExperimentBackgroundDiffing); + const BOOL onBackground = self.config.allowsBackgroundDiffing; if (onBackground) { __weak __typeof__(self) weakSelf = self; dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ diff --git a/Source/IGListKit/Internal/IGListUpdateTransactable.h b/Source/IGListKit/Internal/IGListUpdateTransactable.h index 9e3d1b031..3f4ec3908 100644 --- a/Source/IGListKit/Internal/IGListUpdateTransactable.h +++ b/Source/IGListKit/Internal/IGListUpdateTransactable.h @@ -20,6 +20,7 @@ typedef struct { BOOL singleItemSectionUpdates; BOOL preferItemReloadsForSectionReloads; BOOL allowsReloadingOnTooManyUpdates; + BOOL allowsBackgroundDiffing; IGListExperiment experiments; } IGListUpdateTransactationConfig; diff --git a/Tests/IGListAdapterE2ETests.m b/Tests/IGListAdapterE2ETests.m index 31da8cff0..15f49935e 100644 --- a/Tests/IGListAdapterE2ETests.m +++ b/Tests/IGListAdapterE2ETests.m @@ -2377,7 +2377,7 @@ - (void)test_whenSchedulingItemUpdate_thenChangeDataSource_thatLastestDataIsAppl - (void)test_whenSchedulingSectionUpdate_thenBeginDiffing_thenChangeCollectionView_thatLastestDataIsApplied { IGListAdapterUpdater *updater = (IGListAdapterUpdater *)self.updater; - updater.experiments |= IGListExperimentBackgroundDiffing; + updater.allowsBackgroundDiffing = YES; [self setupWithObjects:@[ genTestObject(@0, @"Foo") @@ -2437,7 +2437,7 @@ - (void)test_whenSchedulingSectionUpdate_thenBeginDiffing_thenChangeCollectionVi - (void)test_whenSchedulingSectionUpdate_thenBeginDiffing_thenChangeTheDataSource_thatLastestDataIsApplied { IGListAdapterUpdater *updater = (IGListAdapterUpdater *)self.updater; - updater.experiments |= IGListExperimentBackgroundDiffing; + updater.allowsBackgroundDiffing = YES; [self setupWithObjects:@[ genTestObject(@0, @"Foo") diff --git a/Tests/IGListAdapterUpdaterTests.m b/Tests/IGListAdapterUpdaterTests.m index e64cd1cc4..a69b1a6ad 100644 --- a/Tests/IGListAdapterUpdaterTests.m +++ b/Tests/IGListAdapterUpdaterTests.m @@ -868,7 +868,7 @@ - (void)test_whenPerformingUpdatesMultipleTimesInARow_thenUpdateWorks { } - (void)test_whenPerformingUpdate_thatCallsDiffingDelegate { - self.updater.experiments |= IGListExperimentBackgroundDiffing; + self.updater.allowsBackgroundDiffing = YES; NSArray *from = @[ [IGSectionObject sectionWithObjects:@[] identifier:@"0"]