Add experiment to skip creating UIViews altogether for constants (#881)

* Add experiment to skip creating UIViews altogether for constants

* Update changelog

* Do it right

* Annotate function

* Skip all the work entirely
This commit is contained in:
Adlai Holler
2018-04-12 10:14:29 -07:00
committed by GitHub
parent 0aefbb65ba
commit 071bd7379f
5 changed files with 38 additions and 18 deletions

View File

@@ -45,6 +45,7 @@
- Use `NS_RETURNS_RETAINED` macro to make our methods a tiny bit faster. [Adlai Holler](https://github.com/Adlai-Holler) [#843](https://github.com/TextureGroup/Texture/pull/843/)
- `ASDisplayNode, ASLayoutSpec, and ASLayoutElementStyle` now conform to `NSLocking`. They act as recursive locks. Useful locking macros have been added as `ASThread.h`. Subclasses / client code can lock these objects but should be careful as usual when dealing with locks. [Adlai Holler](https://github.com/Adlai-Holler)
- Introduces `ASRecursiveUnfairLock` as an experiment to improve locking performance. [Adlai Holler](https://github.com/Adlai-Holler)
- Adds an experiment to shorten init time. [Adlai Holler](https://github.com/Adlai-Holler)
## 2.6
- [Xcode 9] Updated to require Xcode 9 (to fix warnings) [Garrett Moon](https://github.com/garrettmoon)

View File

@@ -24,6 +24,7 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) {
ASExperimentalTextNode = 1 << 1, // exp_text_node
ASExperimentalInterfaceStateCoalescing = 1 << 2, // exp_interface_state_coalesce
ASExperimentalUnfairLock = 1 << 3, // exp_unfair_lock
ASExperimentalLayerDefaults = 1 << 4, // exp_infer_layer_defaults
ASExperimentalFeatureAll = 0xFFFFFFFF
};

View File

@@ -16,7 +16,9 @@ NSArray<NSString *> *ASExperimentalFeaturesGetNames(ASExperimentalFeatures flags
{
NSArray *allNames = ASCreateOnce((@[@"exp_graphics_contexts",
@"exp_text_node",
@"exp_interface_state_coalesce"]));
@"exp_interface_state_coalesce",
@"exp_unfair_lock",
@"exp_infer_layer_defaults"]));
if (flags == ASExperimentalFeatureAll) {
return allNames;

View File

@@ -29,7 +29,7 @@
#import <AsyncDisplayKit/ASConfigurationInternal.h>
#import <AsyncDisplayKit/ASRecursiveUnfairLock.h>
ASDISPLAYNODE_INLINE BOOL ASDisplayNodeThreadIsMain()
ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT BOOL ASDisplayNodeThreadIsMain()
{
return 0 != pthread_main_np();
}

View File

@@ -25,26 +25,42 @@
#import <AsyncDisplayKit/ASRunLoopQueue.h>
#import <AsyncDisplayKit/ASThread.h>
static BOOL defaultAllowsGroupOpacity = YES;
static BOOL defaultAllowsEdgeAntialiasing = NO;
static NSNumber *allowsGroupOpacityFromUIKitOrNil;
static NSNumber *allowsEdgeAntialiasingFromUIKitOrNil;
BOOL ASDefaultAllowsGroupOpacity()
{
static BOOL groupOpacity;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSNumber *groupOpacityObj = allowsGroupOpacityFromUIKitOrNil ?: [NSBundle.mainBundle objectForInfoDictionaryKey:@"UIViewGroupOpacity"];
groupOpacity = groupOpacityObj ? groupOpacityObj.boolValue : YES;
});
return groupOpacity;
}
BOOL ASDefaultAllowsEdgeAntialiasing()
{
static BOOL edgeAntialiasing;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSNumber *antialiasingObj = allowsEdgeAntialiasingFromUIKitOrNil ?: [NSBundle.mainBundle objectForInfoDictionaryKey:@"UIViewEdgeAntialiasing"];
edgeAntialiasing = antialiasingObj ? antialiasingObj.boolValue : NO;
});
return edgeAntialiasing;
}
void ASInitializeFrameworkMainThread(void)
{
ASDisplayNodeThreadIsMain();
ASDisplayNodeCAssertMainThread();
// Ensure these values are cached on the main thread before needed in the background.
if (ASActivateExperimentalFeature(ASExperimentalLayerDefaults)) {
// Nop. We will gather default values on-demand in ASDefaultAllowsGroupOpacity and ASDefaultAllowsEdgeAntialiasing
} else {
CALayer *layer = [[[UIView alloc] init] layer];
defaultAllowsGroupOpacity = layer.allowsGroupOpacity;
defaultAllowsEdgeAntialiasing = layer.allowsEdgeAntialiasing;
allowsGroupOpacityFromUIKitOrNil = @(layer.allowsGroupOpacity);
allowsEdgeAntialiasingFromUIKitOrNil = @(layer.allowsEdgeAntialiasing);
}
BOOL ASDefaultAllowsGroupOpacity(void)
{
return defaultAllowsGroupOpacity;
}
BOOL ASDefaultAllowsEdgeAntialiasing(void)
{
return defaultAllowsEdgeAntialiasing;
}
BOOL ASSubclassOverridesSelector(Class superclass, Class subclass, SEL selector)