Skip to content

Commit

Permalink
Shrink ASDisplayNode from 1072 to 968 bytes, reduction of 10.74% (Tex…
Browse files Browse the repository at this point in the history
…tureGroup#1484)

* Shrink ASDisplayNode from 1088 to 976 bytes, reduction of 11.48%

These objects accumulate in the heap, so reducing their size will allow more to accumulate before memory warnings.

Group the `BOOL`s into a struct. Shrink the various stored `enum`s to fit the size of their contents. Move the ivars around so that the smaller `enum` are near eachother and the bitfield struct.

* Forgot to bit-field-ify placeholderEnable; new small size is 968, old size is 1072 (measured consistentlyl on iPhoneSE simulator). 10.74% reduction.
  • Loading branch information
Greg Bolsinga authored and hebertialmeida committed May 10, 2019
1 parent 44117ea commit 01208b7
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Source/ASDisplayNode+Beta.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ AS_EXTERN void ASPerformBlockOnBackgroundThread(void (^block)(void)); // DISPATC
/**
* Bitmask to indicate what performance measurements the cell should record.
*/
typedef NS_OPTIONS(NSUInteger, ASDisplayNodePerformanceMeasurementOptions) {
typedef NS_OPTIONS(unsigned char, ASDisplayNodePerformanceMeasurementOptions) {
ASDisplayNodePerformanceMeasurementOptionLayoutSpec = 1 << 0,
ASDisplayNodePerformanceMeasurementOptionLayoutComputation = 1 << 1
};
Expand Down
2 changes: 1 addition & 1 deletion Source/ASDisplayNode+InterfaceState.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* The defualt state, ASInterfaceStateNone, means that the element is not predicted to be onscreen soon and
* preloading should not be performed. Swift: use [] for the default behavior.
*/
typedef NS_OPTIONS(NSUInteger, ASInterfaceState)
typedef NS_OPTIONS(unsigned char, ASInterfaceState)
{
/** The element is not predicted to be onscreen soon and preloading should not be performed */
ASInterfaceStateNone = 0,
Expand Down
6 changes: 3 additions & 3 deletions Source/ASDisplayNode+Layout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,13 @@ @implementation ASDisplayNode (ASAutomaticSubnodeManagement)
- (BOOL)automaticallyManagesSubnodes
{
MutexLocker l(__instanceLock__);
return _automaticallyManagesSubnodes;
return _flags.automaticallyManagesSubnodes;
}

- (void)setAutomaticallyManagesSubnodes:(BOOL)automaticallyManagesSubnodes
{
MutexLocker l(__instanceLock__);
_automaticallyManagesSubnodes = automaticallyManagesSubnodes;
_flags.automaticallyManagesSubnodes = automaticallyManagesSubnodes;
}

@end
Expand Down Expand Up @@ -1027,7 +1027,7 @@ - (void)_pendingLayoutTransitionDidComplete
// We generate placeholders at -layoutThatFits: time so that a node is guaranteed to have a placeholder ready to go.
// This is also because measurement is usually asynchronous, but placeholders need to be set up synchronously.
// First measurement is guaranteed to be before the node is onscreen, so we can create the image async. but still have it appear sync.
if (_placeholderEnabled && !_placeholderImage && [self _locked_displaysAsynchronously]) {
if (_flags.placeholderEnabled && !_placeholderImage && [self _locked_displaysAsynchronously]) {

// Zero-sized nodes do not require a placeholder.
CGSize layoutSize = _calculatedDisplayNodeLayout.layout.size;
Expand Down
4 changes: 2 additions & 2 deletions Source/ASDisplayNode+Yoga.mm
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ - (ASLayout *)yogaCalculatedLayout
}

- (BOOL)willApplyNextYogaCalculatedLayout {
return _willApplyNextYogaCalculatedLayout;
return _flags.willApplyNextYogaCalculatedLayout;
}

- (void)setWillApplyNextYogaCalculatedLayout:(BOOL)willApplyNextYogaCalculatedLayout {
_willApplyNextYogaCalculatedLayout = willApplyNextYogaCalculatedLayout;
_flags.willApplyNextYogaCalculatedLayout = willApplyNextYogaCalculatedLayout;
}

- (void)setYogaLayoutInProgress:(BOOL)yogaLayoutInProgress
Expand Down
2 changes: 1 addition & 1 deletion Source/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ typedef ASLayoutSpec * _Nonnull(^ASLayoutSpecBlock)(__kindof ASDisplayNode *node
*/
typedef void (^ASDisplayNodeNonFatalErrorBlock)(NSError *error);

typedef NS_ENUM(NSInteger, ASCornerRoundingType) {
typedef NS_ENUM(unsigned char, ASCornerRoundingType) {
ASCornerRoundingTypeDefaultSlowCALayer,
ASCornerRoundingTypePrecomposited,
ASCornerRoundingTypeClipping
Expand Down
34 changes: 17 additions & 17 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,11 @@ - (void)_initializeInstance
_flags.canCallSetNeedsDisplayOfLayer = YES;

_fallbackSafeAreaInsets = UIEdgeInsetsZero;
_fallbackInsetsLayoutMarginsFromSafeArea = YES;
_isViewControllerRoot = NO;
_flags.fallbackInsetsLayoutMarginsFromSafeArea = YES;
_flags.isViewControllerRoot = NO;

_automaticallyRelayoutOnSafeAreaChanges = NO;
_automaticallyRelayoutOnLayoutMarginsChanges = NO;
_flags.automaticallyRelayoutOnSafeAreaChanges = NO;
_flags.automaticallyRelayoutOnLayoutMarginsChanges = NO;

[self baseDidInit];
}
Expand Down Expand Up @@ -862,37 +862,37 @@ - (void)_fallbackUpdateSafeAreaOnChildren
- (BOOL)isViewControllerRoot
{
MutexLocker l(__instanceLock__);
return _isViewControllerRoot;
return _flags.isViewControllerRoot;
}

- (void)setViewControllerRoot:(BOOL)flag
{
MutexLocker l(__instanceLock__);
_isViewControllerRoot = flag;
_flags.isViewControllerRoot = flag;
}

- (BOOL)automaticallyRelayoutOnSafeAreaChanges
{
MutexLocker l(__instanceLock__);
return _automaticallyRelayoutOnSafeAreaChanges;
return _flags.automaticallyRelayoutOnSafeAreaChanges;
}

- (void)setAutomaticallyRelayoutOnSafeAreaChanges:(BOOL)flag
{
MutexLocker l(__instanceLock__);
_automaticallyRelayoutOnSafeAreaChanges = flag;
_flags.automaticallyRelayoutOnSafeAreaChanges = flag;
}

- (BOOL)automaticallyRelayoutOnLayoutMarginsChanges
{
MutexLocker l(__instanceLock__);
return _automaticallyRelayoutOnLayoutMarginsChanges;
return _flags.automaticallyRelayoutOnLayoutMarginsChanges;
}

- (void)setAutomaticallyRelayoutOnLayoutMarginsChanges:(BOOL)flag
{
MutexLocker l(__instanceLock__);
_automaticallyRelayoutOnLayoutMarginsChanges = flag;
_flags.automaticallyRelayoutOnLayoutMarginsChanges = flag;
}

- (void)__setNodeController:(ASNodeController *)controller
Expand Down Expand Up @@ -2592,7 +2592,7 @@ - (void)_locked_layoutPlaceholderIfNecessary
- (BOOL)_locked_shouldHavePlaceholderLayer
{
DISABLED_ASAssertLocked(__instanceLock__);
return (_placeholderEnabled && [self _implementsDisplay]);
return (_flags.placeholderEnabled && [self _implementsDisplay]);
}

- (void)_locked_setupPlaceholderLayerIfNeeded
Expand Down Expand Up @@ -2637,13 +2637,13 @@ - (BOOL)placeholderShouldPersist
- (BOOL)placeholderEnabled
{
MutexLocker l(__instanceLock__);
return _placeholderEnabled;
return _flags.placeholderEnabled;
}

- (void)setPlaceholderEnabled:(BOOL)placeholderEnabled
{
MutexLocker l(__instanceLock__);
_placeholderEnabled = placeholderEnabled;
_flags.placeholderEnabled = placeholderEnabled;
}

- (NSTimeInterval)placeholderFadeDuration
Expand Down Expand Up @@ -3143,7 +3143,7 @@ - (BOOL)shouldScheduleDisplayWithNewInterfaceState:(ASInterfaceState)newInterfac
- (void)addInterfaceStateDelegate:(id <ASInterfaceStateDelegate>)interfaceStateDelegate
{
MutexLocker l(__instanceLock__);
_hasHadInterfaceStateDelegates = YES;
_flags.hasHadInterfaceStateDelegates = YES;
for (int i = 0; i < AS_MAX_INTERFACE_STATE_DELEGATES; i++) {
if (_interfaceStateDelegates[i] == nil) {
_interfaceStateDelegates[i] = interfaceStateDelegate;
Expand Down Expand Up @@ -3325,7 +3325,7 @@ - (void)enumerateInterfaceStateDelegates:(void (NS_NOESCAPE ^)(id<ASInterfaceSta
{
ASLockScopeSelf();
// Fast path for non-delegating nodes.
if (!_hasHadInterfaceStateDelegates) {
if (!_flags.hasHadInterfaceStateDelegates) {
return;
}

Expand Down Expand Up @@ -3537,13 +3537,13 @@ - (ASDisplayNodePerformanceMeasurements)performanceMeasurements
- (void)setIsAccessibilityContainer:(BOOL)isAccessibilityContainer
{
MutexLocker l(__instanceLock__);
_isAccessibilityContainer = isAccessibilityContainer;
_flags.isAccessibilityContainer = isAccessibilityContainer;
}

- (BOOL)isAccessibilityContainer
{
MutexLocker l(__instanceLock__);
return _isAccessibilityContainer;
return _flags.isAccessibilityContainer;
}

- (NSString *)defaultAccessibilityLabel
Expand Down
2 changes: 1 addition & 1 deletion Source/ASImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ - (void)setPlaceholderColor:(UIColor *)placeholderColor
{
ASLockScopeSelf();
if (ASCompareAssignCopy(_placeholderColor, placeholderColor)) {
_placeholderEnabled = (placeholderColor != nil);
_flags.placeholderEnabled = (placeholderColor != nil);
}
}

Expand Down
7 changes: 1 addition & 6 deletions Source/Private/ASDisplayNode+FrameworkPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
cancelled below the point they are enabled. They continue to the leaves of the hierarchy.
*/

typedef NS_OPTIONS(NSUInteger, ASHierarchyState)
typedef NS_OPTIONS(unsigned char, ASHierarchyState)
{
/** The node may or may not have a supernode, but no supernode has a special hierarchy-influencing option enabled. */
ASHierarchyStateNormal = 0,
Expand Down Expand Up @@ -115,11 +115,6 @@ __unused static NSString * _Nonnull NSStringFromASHierarchyStateChange(ASHierarc
#undef HIERARCHY_STATE_DELTA

@interface ASDisplayNode () <ASDescriptionProvider, ASDebugDescriptionProvider>
{
@protected
ASInterfaceState _interfaceState;
ASHierarchyState _hierarchyState;
}

// The view class to use when creating a new display node instance. Defaults to _ASDisplayView.
+ (Class)viewClass;
Expand Down
20 changes: 10 additions & 10 deletions Source/Private/ASDisplayNode+UIViewBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ - (void)setInsetsLayoutMarginsFromSafeArea:(BOOL)insetsLayoutMarginsFromSafeArea
{
_bridge_prologue_write;

_fallbackInsetsLayoutMarginsFromSafeArea = insetsLayoutMarginsFromSafeArea;
_flags.fallbackInsetsLayoutMarginsFromSafeArea = insetsLayoutMarginsFromSafeArea;

if (AS_AVAILABLE_IOS(11.0)) {
if (!_flags.layerBacked) {
Expand Down Expand Up @@ -1027,7 +1027,7 @@ - (BOOL)_locked_insetsLayoutMarginsFromSafeArea
return _getFromViewOnly(insetsLayoutMarginsFromSafeArea);
}
}
return _fallbackInsetsLayoutMarginsFromSafeArea;
return _flags.fallbackInsetsLayoutMarginsFromSafeArea;
}

@end
Expand Down Expand Up @@ -1056,13 +1056,13 @@ @implementation ASDisplayNode (UIViewBridgeAccessibility)
- (BOOL)isAccessibilityElement
{
_bridge_prologue_read;
return _getAccessibilityFromViewOrProperty(_isAccessibilityElement, isAccessibilityElement);
return _getAccessibilityFromViewOrProperty(_flags.isAccessibilityElement, isAccessibilityElement);
}

- (void)setIsAccessibilityElement:(BOOL)isAccessibilityElement
{
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_isAccessibilityElement, isAccessibilityElement, isAccessibilityElement, isAccessibilityElement);
_setAccessibilityToViewAndProperty(_flags.isAccessibilityElement, isAccessibilityElement, isAccessibilityElement, isAccessibilityElement);
}

- (NSString *)accessibilityLabel
Expand Down Expand Up @@ -1192,37 +1192,37 @@ - (void)setAccessibilityLanguage:(NSString *)accessibilityLanguage
- (BOOL)accessibilityElementsHidden
{
_bridge_prologue_read;
return _getAccessibilityFromViewOrProperty(_accessibilityElementsHidden, accessibilityElementsHidden);
return _getAccessibilityFromViewOrProperty(_flags.accessibilityElementsHidden, accessibilityElementsHidden);
}

- (void)setAccessibilityElementsHidden:(BOOL)accessibilityElementsHidden
{
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_accessibilityElementsHidden, accessibilityElementsHidden, accessibilityElementsHidden, accessibilityElementsHidden);
_setAccessibilityToViewAndProperty(_flags.accessibilityElementsHidden, accessibilityElementsHidden, accessibilityElementsHidden, accessibilityElementsHidden);
}

- (BOOL)accessibilityViewIsModal
{
_bridge_prologue_read;
return _getAccessibilityFromViewOrProperty(_accessibilityViewIsModal, accessibilityViewIsModal);
return _getAccessibilityFromViewOrProperty(_flags.accessibilityViewIsModal, accessibilityViewIsModal);
}

- (void)setAccessibilityViewIsModal:(BOOL)accessibilityViewIsModal
{
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_accessibilityViewIsModal, accessibilityViewIsModal, accessibilityViewIsModal, accessibilityViewIsModal);
_setAccessibilityToViewAndProperty(_flags.accessibilityViewIsModal, accessibilityViewIsModal, accessibilityViewIsModal, accessibilityViewIsModal);
}

- (BOOL)shouldGroupAccessibilityChildren
{
_bridge_prologue_read;
return _getAccessibilityFromViewOrProperty(_shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren);
return _getAccessibilityFromViewOrProperty(_flags.shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren);
}

- (void)setShouldGroupAccessibilityChildren:(BOOL)shouldGroupAccessibilityChildren
{
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren);
_setAccessibilityToViewAndProperty(_flags.shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren);
}

- (NSString *)accessibilityIdentifier
Expand Down
Loading

0 comments on commit 01208b7

Please sign in to comment.