From efeb3d274990de404c52c8b0778f9e554d756184 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Thu, 21 Feb 2019 12:33:40 -0800 Subject: [PATCH] Add an experimental flag to use native dispatch_apply (#1345) * 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 --- Schemas/configuration.json | 3 ++- Source/ASExperimentalFeatures.h | 1 + Source/ASExperimentalFeatures.mm | 3 ++- Source/Private/ASDispatch.mm | 6 ++++++ Tests/ASConfigurationTests.mm | 6 ++++-- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Schemas/configuration.json b/Schemas/configuration.json index 2126fa876..5fb3993b7 100644 --- a/Schemas/configuration.json +++ b/Schemas/configuration.json @@ -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" ] } } diff --git a/Source/ASExperimentalFeatures.h b/Source/ASExperimentalFeatures.h index 8061785a8..96e5127c4 100644 --- a/Source/ASExperimentalFeatures.h +++ b/Source/ASExperimentalFeatures.h @@ -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 }; diff --git a/Source/ASExperimentalFeatures.mm b/Source/ASExperimentalFeatures.mm index 3f005beed..bba80d5e8 100644 --- a/Source/ASExperimentalFeatures.mm +++ b/Source/ASExperimentalFeatures.mm @@ -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; diff --git a/Source/Private/ASDispatch.mm b/Source/Private/ASDispatch.mm index 5c713db80..769a9185d 100644 --- a/Source/Private/ASDispatch.mm +++ b/Source/Private/ASDispatch.mm @@ -7,6 +7,8 @@ // #import +#import + // Prefer C atomics in this file because ObjC blocks can't capture C++ atomics well. #import @@ -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(); diff --git a/Tests/ASConfigurationTests.mm b/Tests/ASConfigurationTests.mm index b5aeeb656..4dd8de2ab 100644 --- a/Tests/ASConfigurationTests.mm +++ b/Tests/ASConfigurationTests.mm @@ -30,7 +30,8 @@ ASExperimentalDidEnterPreloadSkipASMLayout, ASExperimentalDisableAccessibilityCache, ASExperimentalSkipAccessibilityWait, - ASExperimentalNewDefaultCellLayoutMode + ASExperimentalNewDefaultCellLayoutMode, + ASExperimentalDispatchApply }; @interface ASConfigurationTests : ASTestCase @@ -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" ]; }