Skip to content

Commit

Permalink
Add experiment to skip creating UIViews altogether for constants (#881)
Browse files Browse the repository at this point in the history
* Add experiment to skip creating UIViews altogether for constants

* Update changelog

* Do it right

* Annotate function

* Skip all the work entirely
  • Loading branch information
Adlai-Holler committed Apr 12, 2018
1 parent 0aefbb6 commit 071bd73
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Source/ASExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
4 changes: 3 additions & 1 deletion Source/ASExperimentalFeatures.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
{
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;
Expand Down
2 changes: 1 addition & 1 deletion Source/Details/ASThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
40 changes: 28 additions & 12 deletions Source/Private/ASInternalHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

void ASInitializeFrameworkMainThread(void)
BOOL ASDefaultAllowsGroupOpacity()
{
ASDisplayNodeThreadIsMain();
// Ensure these values are cached on the main thread before needed in the background.
CALayer *layer = [[[UIView alloc] init] layer];
defaultAllowsGroupOpacity = layer.allowsGroupOpacity;
defaultAllowsEdgeAntialiasing = layer.allowsEdgeAntialiasing;
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 ASDefaultAllowsGroupOpacity(void)
BOOL ASDefaultAllowsEdgeAntialiasing()
{
return defaultAllowsGroupOpacity;
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;
}

BOOL ASDefaultAllowsEdgeAntialiasing(void)
void ASInitializeFrameworkMainThread(void)
{
return defaultAllowsEdgeAntialiasing;
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];
allowsGroupOpacityFromUIKitOrNil = @(layer.allowsGroupOpacity);
allowsEdgeAntialiasingFromUIKitOrNil = @(layer.allowsEdgeAntialiasing);
}
}

BOOL ASSubclassOverridesSelector(Class superclass, Class subclass, SEL selector)
Expand Down

0 comments on commit 071bd73

Please sign in to comment.