From 985bf48ce0794fc98ea1a4ea168e987135f05290 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Thu, 26 Jul 2018 09:11:12 -0700 Subject: [PATCH] Default to using display handler for improved scroll perf Summary: After experimenting with scroll performance gains, default `IGListAdapter` behavior to use the faster means of collecting visible section controllers. Reviewed By: maxoll Differential Revision: D8543686 fbshipit-source-id: e33a78c0f1d4f208705ff5d490ab032eb6c36e70 --- Source/Common/IGListExperiments.h | 2 -- Source/IGListAdapter.m | 22 ------------------- Tests/IGListAdapterTests.m | 35 ------------------------------- 3 files changed, 59 deletions(-) diff --git a/Source/Common/IGListExperiments.h b/Source/Common/IGListExperiments.h index f38155cd..cb42c666 100644 --- a/Source/Common/IGListExperiments.h +++ b/Source/Common/IGListExperiments.h @@ -20,8 +20,6 @@ typedef NS_OPTIONS (NSInteger, IGListExperiment) { IGListExperimentBackgroundDiffing = 1 << 2, /// Test fallback to reloadData when "too many" update operations. IGListExperimentReloadDataFallback = 1 << 3, - /// Test a faster way to return visible section controllers. - IGListExperimentFasterVisibleSectionController = 1 << 4, /// Test deduping item-level updates. IGListExperimentDedupeItemUpdates = 1 << 5, /// Test deferring object creation until just before diffing. diff --git a/Source/IGListAdapter.m b/Source/IGListAdapter.m index 936f9b81..f45ad5b8 100644 --- a/Source/IGListAdapter.m +++ b/Source/IGListAdapter.m @@ -507,28 +507,6 @@ - (NSArray *)visibleSectionControllers { IGAssertMainThread(); - if (IGListExperimentEnabled(self.experiments, IGListExperimentFasterVisibleSectionController)) { - return [self _visibleSectionControllersFromDisplayHandler]; - } else { - return [self _visibleSectionControllersFromLayoutAttributes]; - } -} - -- (NSArray *)_visibleSectionControllersFromLayoutAttributes { - NSMutableSet *visibleSectionControllers = [NSMutableSet new]; - NSArray *attributes = - [self.collectionView.collectionViewLayout layoutAttributesForElementsInRect:self.collectionView.bounds]; - for (UICollectionViewLayoutAttributes* attribute in attributes) { - IGListSectionController *sectionController = [self sectionControllerForSection:attribute.indexPath.section]; - IGAssert(sectionController != nil, @"Section controller nil for cell in section %ld", (long)attribute.indexPath.section); - if (sectionController) { - [visibleSectionControllers addObject:sectionController]; - } - } - return [visibleSectionControllers allObjects]; -} - -- (NSArray *)_visibleSectionControllersFromDisplayHandler { return [[self.displayHandler visibleListSections] allObjects]; } diff --git a/Tests/IGListAdapterTests.m b/Tests/IGListAdapterTests.m index 9a75caad..f3bd7536 100644 --- a/Tests/IGListAdapterTests.m +++ b/Tests/IGListAdapterTests.m @@ -271,22 +271,6 @@ XCTAssertTrue([visibleSectionControllers containsObject:[self.adapter sectionControllerForObject:@4]]); } -- (void)test_whenCellsExtendBeyondBounds_withFasterExperiment_thatVisibleSectionControllersAreLimited { - // add experiment - self.adapter.experiments |= IGListExperimentFasterVisibleSectionController; - // # of items for each object == [item integerValue], so @2 has 2 items (cells) - self.dataSource.objects = @[@1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12]; - [self.adapter reloadDataWithCompletion:nil]; - XCTAssertEqual([self.collectionView numberOfSections], 12); - NSArray *visibleSectionControllers = [self.adapter visibleSectionControllers]; - // UIWindow is 100x100, each cell is 100x10 so should have the following section/cell count: 1 + 2 + 3 + 4 = 10 (100 tall) - XCTAssertEqual(visibleSectionControllers.count, 4); - XCTAssertTrue([visibleSectionControllers containsObject:[self.adapter sectionControllerForObject:@1]]); - XCTAssertTrue([visibleSectionControllers containsObject:[self.adapter sectionControllerForObject:@2]]); - XCTAssertTrue([visibleSectionControllers containsObject:[self.adapter sectionControllerForObject:@3]]); - XCTAssertTrue([visibleSectionControllers containsObject:[self.adapter sectionControllerForObject:@4]]); -} - - (void) test_withEmptySectionPlusFooter_thatVisibleSectionControllersAreCorrect { self.dataSource.objects = @[@0]; [self.adapter reloadDataWithCompletion:nil]; @@ -304,25 +288,6 @@ XCTAssertTrue(visibleSectionControllers.firstObject.supplementaryViewSource == supplementarySource); } -- (void) test_withEmptySectionPlusFooter_withFasterExperiment_thatVisibleSectionControllersAreCorrect { - // add experiment - self.adapter.experiments |= IGListExperimentFasterVisibleSectionController; - self.dataSource.objects = @[@0]; - [self.adapter reloadDataWithCompletion:nil]; - IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new]; - supplementarySource.dequeueFromNib = YES; - supplementarySource.collectionContext = self.adapter; - supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionFooter]; - IGListSectionController *controller = [self.adapter sectionControllerForObject:@0]; - controller.supplementaryViewSource = supplementarySource; - supplementarySource.sectionController = controller; - [self.adapter performUpdatesAnimated:NO completion:nil]; - NSArray *visibleSectionControllers = [self.adapter visibleSectionControllers]; - - XCTAssertTrue([visibleSectionControllers count] == 1); - XCTAssertTrue(visibleSectionControllers.firstObject.supplementaryViewSource == supplementarySource); -} - - (void)test_whenCellsExtendBeyondBounds_thatVisibleCellsExistForSectionControllers { self.dataSource.objects = @[@2, @3, @4, @5, @6]; [self.adapter reloadDataWithCompletion:nil];