Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an experimental flag to use native dispatch_apply #1345

Merged
merged 2 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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