Skip to content

Commit

Permalink
[ASDataController] Add an experiment that avoids flushing editing que…
Browse files Browse the repository at this point in the history
…ue before starting the data pipeline pipeline (TextureGroup#1564)

* [ASDataController] Avoid flushing editing queue before starting data controller pipeline

Step 1 of the pipeline is on main thread and needs pendingMap which was updated by the end of step 1 of the run. And step 1 operates on data source index space. So it should be ok to start it ASAP -- without waiting for any running work on the background editing queue.

One potential race condition after this change is that it's possible for main thread to query the data source (step 1) while the editing queue consumes the last change set (step 3). However, as long as the client's each nodeBlock and the node's layout code capture/reference an individual model object (as opposed to the whole data set) -- which is what clients are supposed to do anyways, then everything should be fine.

The benefit of this diff is that the pipeline will be able to accept many more change sets within a short time window, for example when clients submit a burst of separate small updates.

I tested this diff against our test suite several times and smoke tested it in our code base without any issues.

* Wrap in an experiment

* Enable experiment in tests

* Minor change
  • Loading branch information
nguyenhuy authored Jul 1, 2019
1 parent 59ab0e8 commit 6e46d9b
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Source/ASExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) {
ASExperimentalSkipClearData = 1 << 6, // exp_skip_clear_data
ASExperimentalDidEnterPreloadSkipASMLayout = 1 << 7, // exp_did_enter_preload_skip_asm_layout
ASExperimentalDispatchApply = 1 << 8, // exp_dispatch_apply
ASExperimentalOOMBackgroundDeallocDisable = 1 << 9, // exp_oom_bg_dealloc_disable
ASExperimentalOOMBackgroundDeallocDisable = 1 << 9, // exp_oom_bg_dealloc_disable
ASExperimentalRemoveTextKitInitialisingLock = 1 << 10, // exp_remove_textkit_initialising_lock
ASExperimentalDrawingGlobal = 1 << 11, // exp_drawing_global
ASExperimentalOptimizeDataControllerPipeline = 1 << 12, // exp_optimize_data_controller_pipeline
ASExperimentalFeatureAll = 0xFFFFFFFF
};

Expand Down
3 changes: 2 additions & 1 deletion Source/ASExperimentalFeatures.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
@"exp_dispatch_apply",
@"exp_oom_bg_dealloc_disable",
@"exp_remove_textkit_initialising_lock",
@"exp_drawing_global"]));
@"exp_drawing_global",
@"exp_optimize_data_controller_pipeline"]));
if (flags == ASExperimentalFeatureAll) {
return allNames;
}
Expand Down
14 changes: 8 additions & 6 deletions Source/Details/ASDataController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,15 @@ - (void)updateWithChangeSet:(_ASHierarchyChangeSet *)changeSet
} else {
os_log_debug(ASCollectionLog(), "performBatchUpdates %@ %@", ASViewToDisplayNode(ASDynamicCast(self.dataSource, UIView)), changeSet);
}

NSTimeInterval transactionQueueFlushDuration = 0.0f;
{
AS::ScopeTimer t(transactionQueueFlushDuration);
dispatch_group_wait(_editingTransactionGroup, DISPATCH_TIME_FOREVER);

if (!ASActivateExperimentalFeature(ASExperimentalOptimizeDataControllerPipeline)) {
NSTimeInterval transactionQueueFlushDuration = 0.0f;
{
AS::ScopeTimer t(transactionQueueFlushDuration);
dispatch_group_wait(_editingTransactionGroup, DISPATCH_TIME_FOREVER);
}
}

// If the initial reloadData has not been called, just bail because we don't have our old data source counts.
// See ASUICollectionViewTests.testThatIssuingAnUpdateBeforeInitialReloadIsUnacceptable
// for the issue that UICollectionView has that we're choosing to workaround.
Expand Down
5 changes: 5 additions & 0 deletions Tests/ASCollectionModernDataSourceTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ @implementation ASCollectionModernDataSourceTests {

- (void)setUp {
[super setUp];

ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalOptimizeDataControllerPipeline;
[ASConfigurationManager test_resetWithConfiguration:config];

// Default is 2 sections: 2 items in first, 1 item in second.
sections = [NSMutableArray array];
[sections addObject:[ASTestSection new]];
Expand Down
12 changes: 11 additions & 1 deletion Tests/ASCollectionViewTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#import <OCMock/OCMock.h>
#import <AsyncDisplayKit/ASCollectionView+Undeprecated.h>
#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h>

#import "ASDisplayNodeTestsHelper.h"
#import "ASTestCase.h"

@interface ASTextCellNodeWithSetSelectedCounter : ASTextCellNode

Expand Down Expand Up @@ -166,12 +168,20 @@ @interface ASCollectionView (InternalTesting)

@end

@interface ASCollectionViewTests : XCTestCase
@interface ASCollectionViewTests : ASTestCase

@end

@implementation ASCollectionViewTests

- (void)setUp
{
[super setUp];
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalOptimizeDataControllerPipeline;
[ASConfigurationManager test_resetWithConfiguration:config];
}

- (void)tearDown
{
// We can't prevent the system from retaining windows, but we can at least clear them out to avoid
Expand Down
12 changes: 11 additions & 1 deletion Tests/ASCollectionViewThrashTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
#import <AsyncDisplayKit/ASCollectionView.h>
#import <stdatomic.h>

#import "ASTestCase.h"
#import "ASThrashUtility.h"

@interface ASCollectionViewThrashTests : XCTestCase
@interface ASCollectionViewThrashTests : ASTestCase

@end

Expand All @@ -25,8 +26,17 @@ @implementation ASCollectionViewThrashTests
BOOL _failed;
}

- (void)setUp
{
[super setUp];
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalOptimizeDataControllerPipeline;
[ASConfigurationManager test_resetWithConfiguration:config];
}

- (void)tearDown
{
[super tearDown];
if (_failed && _update != nil) {
NSLog(@"Failed update %@: %@", _update, _update.logFriendlyBase64Representation);
}
Expand Down
9 changes: 6 additions & 3 deletions Tests/ASConfigurationTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
ASExperimentalDispatchApply,
ASExperimentalOOMBackgroundDeallocDisable,
ASExperimentalRemoveTextKitInitialisingLock,
ASExperimentalDrawingGlobal
ASExperimentalDrawingGlobal,
ASExperimentalOptimizeDataControllerPipeline
};

@interface ASConfigurationTests : ASTestCase <ASConfigurationDelegate>
Expand All @@ -53,11 +54,13 @@ + (NSArray *)names {
@"exp_dispatch_apply",
@"exp_oom_bg_dealloc_disable",
@"exp_remove_textkit_initialising_lock",
@"exp_drawing_global"
@"exp_drawing_global",
@"exp_optimize_data_controller_pipeline"
];
}

- (ASExperimentalFeatures)allFeatures {
- (ASExperimentalFeatures)allFeatures
{
ASExperimentalFeatures allFeatures = 0;
for (int i = 0; i < sizeof(features)/sizeof(ASExperimentalFeatures); i++) {
allFeatures |= features[i];
Expand Down
11 changes: 10 additions & 1 deletion Tests/ASTableViewTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import <AsyncDisplayKit/ASTableView+Undeprecated.h>
#import <AsyncDisplayKit/ASInternalHelpers.h>

#import "ASTestCase.h"
#import "ASXCTExtensions.h"

#define NumberOfSections 10
Expand Down Expand Up @@ -217,12 +218,20 @@ - (ASSizeRange)tableView:(ASTableView *)tableView constrainedSizeForRowAtIndexPa

@end

@interface ASTableViewTests : XCTestCase
@interface ASTableViewTests : ASTestCase
@property (nonatomic, retain) ASTableView *testTableView;
@end

@implementation ASTableViewTests

- (void)setUp
{
[super setUp];
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalOptimizeDataControllerPipeline;
[ASConfigurationManager test_resetWithConfiguration:config];
}

- (void)testDataSourceImplementsNecessaryMethods
{
ASTestTableView *tableView = [[ASTestTableView alloc] __initWithFrame:CGRectMake(0, 0, 100, 400)
Expand Down
12 changes: 11 additions & 1 deletion Tests/ASTableViewThrashTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#import <AsyncDisplayKit/ASTableView+Undeprecated.h>
#import <stdatomic.h>

#import "ASTestCase.h"
#import "ASThrashUtility.h"

@interface ASTableViewThrashTests: XCTestCase
@interface ASTableViewThrashTests: ASTestCase
@end

@implementation ASTableViewThrashTests
Expand All @@ -27,8 +28,17 @@ @implementation ASTableViewThrashTests

#pragma mark Overrides

- (void)setUp
{
[super setUp];
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalOptimizeDataControllerPipeline;
[ASConfigurationManager test_resetWithConfiguration:config];
}

- (void)tearDown
{
[super tearDown];
if (_failed && _update != nil) {
NSLog(@"Failed update %@: %@", _update, _update.logFriendlyBase64Representation);
}
Expand Down

0 comments on commit 6e46d9b

Please sign in to comment.