Skip to content

Commit

Permalink
Add an experimental flag to use native dispatch_apply (#1345)
Browse files Browse the repository at this point in the history
* Add an experimental flag to use native dispatch_apply instead of our core count * 2 approach. This has shown performance wins in some profiling.

* Add in other places
  • Loading branch information
Adlai-Holler authored and nguyenhuy committed Feb 22, 2019
1 parent f728d80 commit 89346fb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Schemas/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"exp_did_enter_preload_skip_asm_layout",
"exp_disable_a11y_cache",
"exp_skip_a11y_wait",
"exp_new_default_cell_layout_mode"
"exp_new_default_cell_layout_mode",
"exp_dispatch_apply"
]
}
}
Expand Down
1 change: 1 addition & 0 deletions Source/ASExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) {
ASExperimentalDisableAccessibilityCache = 1 << 10, // exp_disable_a11y_cache
ASExperimentalSkipAccessibilityWait = 1 << 11, // exp_skip_a11y_wait
ASExperimentalNewDefaultCellLayoutMode = 1 << 12, // exp_new_default_cell_layout_mode
ASExperimentalDispatchApply = 1 << 13, // exp_dispatch_apply
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 @@ -24,7 +24,8 @@
@"exp_did_enter_preload_skip_asm_layout",
@"exp_disable_a11y_cache",
@"exp_skip_a11y_wait",
@"exp_new_default_cell_layout_mode"]));
@"exp_new_default_cell_layout_mode",
@"exp_dispatch_apply"]));

if (flags == ASExperimentalFeatureAll) {
return allNames;
Expand Down
6 changes: 6 additions & 0 deletions Source/Private/ASDispatch.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//

#import <AsyncDisplayKit/ASDispatch.h>
#import <AsyncDisplayKit/ASConfigurationInternal.h>


// Prefer C atomics in this file because ObjC blocks can't capture C++ atomics well.
#import <stdatomic.h>
Expand All @@ -19,6 +21,10 @@
*/
void ASDispatchApply(size_t iterationCount, dispatch_queue_t queue, NSUInteger threadCount, NS_NOESCAPE void(^work)(size_t i)) {
if (threadCount == 0) {
if (ASActivateExperimentalFeature(ASExperimentalDispatchApply)) {
dispatch_apply(iterationCount, queue, work);
return;
}
threadCount = NSProcessInfo.processInfo.activeProcessorCount * 2;
}
dispatch_group_t group = dispatch_group_create();
Expand Down
6 changes: 4 additions & 2 deletions Tests/ASConfigurationTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
ASExperimentalDidEnterPreloadSkipASMLayout,
ASExperimentalDisableAccessibilityCache,
ASExperimentalSkipAccessibilityWait,
ASExperimentalNewDefaultCellLayoutMode
ASExperimentalNewDefaultCellLayoutMode,
ASExperimentalDispatchApply
};

@interface ASConfigurationTests : ASTestCase <ASConfigurationDelegate>
Expand All @@ -55,7 +56,8 @@ + (NSArray *)names {
@"exp_did_enter_preload_skip_asm_layout",
@"exp_disable_a11y_cache",
@"exp_skip_a11y_wait",
@"exp_new_default_cell_layout_mode"
@"exp_new_default_cell_layout_mode",
@"exp_dispatch_apply"
];
}

Expand Down

0 comments on commit 89346fb

Please sign in to comment.