From 784f1beb9f8db5d6c156a92ce6a93b122d3f856b Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Tue, 10 Apr 2018 13:39:47 -0700 Subject: [PATCH] Add experimental update coalescance feature and test Summary: Testing out new coalescence ideas after talking with @[100001606943892:tweilu]. Theory is that we can reduce stalls and improve scroll performance by batching more updates into one. Need to test this out first. Differential Revision: D7565003 fbshipit-source-id: b2e9fa39d52cc0b7aa59c2bfad709804ba0a0b63 --- Source/IGListAdapterUpdater.h | 5 +++++ Source/IGListAdapterUpdater.m | 7 ++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/IGListAdapterUpdater.h b/Source/IGListAdapterUpdater.h index b772a95f..f4dc7016 100644 --- a/Source/IGListAdapterUpdater.h +++ b/Source/IGListAdapterUpdater.h @@ -49,6 +49,11 @@ NS_SWIFT_NAME(ListAdapterUpdater) */ @property (nonatomic, assign) BOOL allowsBackgroundReloading; +/** + Time, in seconds, to wait and coalesce batch updates. Default is 0. + */ +@property (nonatomic, assign) NSTimeInterval coalescanceTime; + /** A bitmask of experiments to conduct on the updater. */ diff --git a/Source/IGListAdapterUpdater.m b/Source/IGListAdapterUpdater.m index 6ec98a16..22f5a613 100644 --- a/Source/IGListAdapterUpdater.m +++ b/Source/IGListAdapterUpdater.m @@ -369,11 +369,8 @@ void convertReloadToDeleteInsert(NSMutableIndexSet *reloads, __weak __typeof__(self) weakSelf = self; __weak __typeof__(collectionView) weakCollectionView = collectionView; - // dispatch_async to give the main queue time to collect more batch updates so that a minimum amount of work - // (diffing, etc) is done on main. dispatch_async does not garauntee a full runloop turn will pass though. - // see -performUpdateWithCollectionView:fromObjects:toObjects:animated:]objectTransitionBlock:completion: for more - // details on how coalescence is done. - dispatch_async(dispatch_get_main_queue(), ^{ + // dispatch after a given amount of time to coalesce other updates and execute as one + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, self.coalescanceTime * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ if (weakSelf.state != IGListBatchUpdateStateIdle || ![weakSelf hasChanges]) { return;