Micro-optimizations in ASDisplayNode that help reduce overhead when recursing large hierarchies.

This commit is contained in:
Scott Goodson
2016-02-05 21:43:14 -08:00
parent 1d84fc4874
commit 9e87813425
2 changed files with 9 additions and 1 deletions

View File

@@ -1405,6 +1405,10 @@ static NSInteger incrementIfFound(NSInteger i) {
{
ASDisplayNodeAssertMainThread();
ASDisplayNodeAssert(!_flags.isEnteringHierarchy, @"Should not cause recursive __enterHierarchy");
// Profiling has shown that locking this method is benificial, so each of the property accesses don't have to lock and unlock.
ASDN::MutexLocker l(_propertyLock);
if (!self.inHierarchy && !_flags.visibilityNotificationsDisabled && ![self __selfOrParentHasVisibilityNotificationsDisabled]) {
self.inHierarchy = YES;
_flags.isEnteringHierarchy = YES;
@@ -1427,6 +1431,10 @@ static NSInteger incrementIfFound(NSInteger i) {
{
ASDisplayNodeAssertMainThread();
ASDisplayNodeAssert(!_flags.isExitingHierarchy, @"Should not cause recursive __exitHierarchy");
// Profiling has shown that locking this method is benificial, so each of the property accesses don't have to lock and unlock.
ASDN::MutexLocker l(_propertyLock);
if (self.inHierarchy && !_flags.visibilityNotificationsDisabled && ![self __selfOrParentHasVisibilityNotificationsDisabled]) {
self.inHierarchy = NO;

View File

@@ -43,7 +43,7 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo
// Allow 2^n increments of begin disabling hierarchy notifications
#define VISIBILITY_NOTIFICATIONS_DISABLED_BITS 4
#define TIME_DISPLAYNODE_OPS (DEBUG || PROFILE)
#define TIME_DISPLAYNODE_OPS 0 // If you're using this information frequently, try: (DEBUG || PROFILE)
@interface ASDisplayNode ()
{