mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Revise performance measurement naming and structure (#2265)
* Revise performance measurement naming and structure - Revises naming from LayoutSpecGeneration to LayoutSpecComputation - Adds a struct instead of an NSDictionary to retrieve performance metrics - Includes ASEnvironmentStatePropagateDown in LayoutSpecComputation measurements * Revise SumScopeTimer to include enable flag * Make struct a typedef
This commit is contained in:
committed by
Adlai Holler
parent
5990376f68
commit
71fc2dd18d
@@ -38,16 +38,15 @@ ASDISPLAYNODE_EXTERN_C_END
|
|||||||
*/
|
*/
|
||||||
typedef NS_OPTIONS(NSUInteger, ASDisplayNodePerformanceMeasurementOptions) {
|
typedef NS_OPTIONS(NSUInteger, ASDisplayNodePerformanceMeasurementOptions) {
|
||||||
ASDisplayNodePerformanceMeasurementOptionLayoutSpec = 1 << 0,
|
ASDisplayNodePerformanceMeasurementOptionLayoutSpec = 1 << 0,
|
||||||
ASDisplayNodePerformanceMeasurementOptionLayoutGeneration = 1 << 1
|
ASDisplayNodePerformanceMeasurementOptionLayoutComputation = 1 << 1
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
typedef struct {
|
||||||
* Keys to retrieve performance entries from the performance dictionary.
|
CFTimeInterval layoutSpecTotalTime;
|
||||||
*/
|
NSInteger layoutSpecNumberOfPasses;
|
||||||
extern NSString *const ASDisplayNodeLayoutSpecTotalTimeKey;
|
CFTimeInterval layoutComputationTotalTime;
|
||||||
extern NSString *const ASDisplayNodeLayoutSpecNumberOfPassesKey;
|
NSInteger layoutComputationNumberOfPasses;
|
||||||
extern NSString *const ASDisplayNodeLayoutGenerationTotalTimeKey;
|
} ASDisplayNodePerformanceMeasurements;
|
||||||
extern NSString *const ASDisplayNodeLayoutGenerationNumberOfPassesKey;
|
|
||||||
|
|
||||||
@interface ASDisplayNode (Beta)
|
@interface ASDisplayNode (Beta)
|
||||||
|
|
||||||
@@ -94,10 +93,9 @@ extern NSString *const ASDisplayNodeLayoutGenerationNumberOfPassesKey;
|
|||||||
@property (nonatomic, assign) ASDisplayNodePerformanceMeasurementOptions measurementOptions;
|
@property (nonatomic, assign) ASDisplayNodePerformanceMeasurementOptions measurementOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract A dictionary representing performance measurements collected.
|
* @abstract A simple struct representing performance measurements collected.
|
||||||
* @note see the constants above to retrieve relevant performance measurements
|
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, strong, readonly) NSDictionary *performanceMeasurements;
|
@property (nonatomic, assign, readonly) ASDisplayNodePerformanceMeasurements performanceMeasurements;
|
||||||
|
|
||||||
/** @name Layout Transitioning */
|
/** @name Layout Transitioning */
|
||||||
|
|
||||||
|
|||||||
@@ -38,11 +38,6 @@
|
|||||||
NSInteger const ASDefaultDrawingPriority = ASDefaultTransactionPriority;
|
NSInteger const ASDefaultDrawingPriority = ASDefaultTransactionPriority;
|
||||||
NSString * const ASRenderingEngineDidDisplayScheduledNodesNotification = @"ASRenderingEngineDidDisplayScheduledNodes";
|
NSString * const ASRenderingEngineDidDisplayScheduledNodesNotification = @"ASRenderingEngineDidDisplayScheduledNodes";
|
||||||
NSString * const ASRenderingEngineDidDisplayNodesScheduledBeforeTimestamp = @"ASRenderingEngineDidDisplayNodesScheduledBeforeTimestamp";
|
NSString * const ASRenderingEngineDidDisplayNodesScheduledBeforeTimestamp = @"ASRenderingEngineDidDisplayNodesScheduledBeforeTimestamp";
|
||||||
NSString * const ASDisplayNodeLayoutSpecTotalTimeKey = @"ASDisplayNodeLayoutSpecTotalTime";
|
|
||||||
NSString * const ASDisplayNodeLayoutSpecNumberOfPassesKey = @"ASDisplayNodeLayoutSpecNumberOfPasses";
|
|
||||||
NSString * const ASDisplayNodeLayoutGenerationTotalTimeKey = @"ASDisplayNodeLayoutGenerationTotalTime";
|
|
||||||
NSString * const ASDisplayNodeLayoutGenerationNumberOfPassesKey = @"ASDisplayNodeLayoutGenerationNumberOfPasses";
|
|
||||||
|
|
||||||
|
|
||||||
// Forward declare CALayerDelegate protocol as the iOS 10 SDK moves CALayerDelegate from a formal delegate to a protocol.
|
// Forward declare CALayerDelegate protocol as the iOS 10 SDK moves CALayerDelegate from a formal delegate to a protocol.
|
||||||
// We have to forward declare the protocol as this place otherwise it will not compile compiling with an Base SDK < iOS 10
|
// We have to forward declare the protocol as this place otherwise it will not compile compiling with an Base SDK < iOS 10
|
||||||
@@ -1227,17 +1222,17 @@ ASLayoutableSizeHelperForwarding
|
|||||||
return _measurementOptions;
|
return _measurementOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary *)performanceMeasurements
|
- (ASDisplayNodePerformanceMeasurements)performanceMeasurements
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
ASDN::MutexLocker l(__instanceLock__);
|
||||||
NSMutableDictionary *measurements = [NSMutableDictionary dictionaryWithCapacity:4];
|
ASDisplayNodePerformanceMeasurements measurements = { .layoutSpecNumberOfPasses = -1, .layoutSpecTotalTime = NAN, .layoutComputationNumberOfPasses = -1, .layoutComputationTotalTime = NAN };
|
||||||
if (_measurementOptions & ASDisplayNodePerformanceMeasurementOptionLayoutSpec) {
|
if (_measurementOptions & ASDisplayNodePerformanceMeasurementOptionLayoutSpec) {
|
||||||
measurements[ASDisplayNodeLayoutSpecTotalTimeKey] = @(_layoutSpecTotalTime);
|
measurements.layoutSpecNumberOfPasses = _layoutSpecNumberOfPasses;
|
||||||
measurements[ASDisplayNodeLayoutSpecNumberOfPassesKey] = @(_layoutSpecNumberOfPasses);
|
measurements.layoutSpecTotalTime = _layoutSpecTotalTime;
|
||||||
}
|
}
|
||||||
if (_measurementOptions & ASDisplayNodePerformanceMeasurementOptionLayoutGeneration) {
|
if (_measurementOptions & ASDisplayNodePerformanceMeasurementOptionLayoutComputation) {
|
||||||
measurements[ASDisplayNodeLayoutGenerationTotalTimeKey] = @(_layoutGenerationTotalTime);
|
measurements.layoutComputationNumberOfPasses = _layoutComputationNumberOfPasses;
|
||||||
measurements[ASDisplayNodeLayoutGenerationNumberOfPassesKey] = @(_layoutGenerationNumberOfPasses);
|
measurements.layoutComputationTotalTime = _layoutComputationTotalTime;
|
||||||
}
|
}
|
||||||
return measurements;
|
return measurements;
|
||||||
}
|
}
|
||||||
@@ -2433,34 +2428,37 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
|
|||||||
|
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
ASDN::MutexLocker l(__instanceLock__);
|
||||||
if ((_methodOverrides & ASDisplayNodeMethodOverrideLayoutSpecThatFits) || _layoutSpecBlock != NULL) {
|
if ((_methodOverrides & ASDisplayNodeMethodOverrideLayoutSpecThatFits) || _layoutSpecBlock != NULL) {
|
||||||
ASLayoutSpec *layoutSpec = nil;
|
BOOL measureLayoutSpec = _measurementOptions & ASDisplayNodePerformanceMeasurementOptionLayoutSpec;
|
||||||
// optional performance measurement for cell nodes
|
if (measureLayoutSpec) {
|
||||||
if (_measurementOptions & ASDisplayNodePerformanceMeasurementOptionLayoutSpec) {
|
|
||||||
ASDN::SumScopeTimer t(_layoutSpecTotalTime);
|
|
||||||
_layoutSpecNumberOfPasses++;
|
_layoutSpecNumberOfPasses++;
|
||||||
layoutSpec = [self layoutSpecThatFits:constrainedSize];
|
|
||||||
} else {
|
|
||||||
layoutSpec = [self layoutSpecThatFits:constrainedSize];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASLayoutSpec *layoutSpec = ({
|
||||||
|
ASDN::SumScopeTimer t(_layoutSpecTotalTime, measureLayoutSpec);
|
||||||
|
[self layoutSpecThatFits:constrainedSize];
|
||||||
|
});
|
||||||
|
|
||||||
ASDisplayNodeAssert(layoutSpec.isMutable, @"Node %@ returned layout spec %@ that has already been used. Layout specs should always be regenerated.", self, layoutSpec);
|
ASDisplayNodeAssert(layoutSpec.isMutable, @"Node %@ returned layout spec %@ that has already been used. Layout specs should always be regenerated.", self, layoutSpec);
|
||||||
|
|
||||||
layoutSpec.parent = self; // This causes upward propogation of any non-default layoutable values.
|
layoutSpec.parent = self; // This causes upward propogation of any non-default layoutable values.
|
||||||
|
|
||||||
// manually propagate the trait collection here so that any layoutSpec children of layoutSpec will get a traitCollection
|
// manually propagate the trait collection here so that any layoutSpec children of layoutSpec will get a traitCollection
|
||||||
ASEnvironmentStatePropagateDown(layoutSpec, self.environmentTraitCollection);
|
{
|
||||||
|
ASDN::SumScopeTimer t(_layoutSpecTotalTime, measureLayoutSpec);
|
||||||
|
ASEnvironmentStatePropagateDown(layoutSpec, self.environmentTraitCollection);
|
||||||
|
}
|
||||||
|
|
||||||
layoutSpec.isMutable = NO;
|
layoutSpec.isMutable = NO;
|
||||||
ASLayout *layout = nil;
|
BOOL measureLayoutComputation = _measurementOptions & ASDisplayNodePerformanceMeasurementOptionLayoutComputation;
|
||||||
// optional performance measurement for cell nodes
|
if (measureLayoutComputation) {
|
||||||
if (_measurementOptions & ASDisplayNodePerformanceMeasurementOptionLayoutGeneration) {
|
_layoutComputationNumberOfPasses++;
|
||||||
ASDN::SumScopeTimer t(_layoutGenerationTotalTime);
|
|
||||||
_layoutGenerationNumberOfPasses++;
|
|
||||||
layout = [layoutSpec layoutThatFits:constrainedSize];
|
|
||||||
} else {
|
|
||||||
layout = [layoutSpec layoutThatFits:constrainedSize];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASLayout *layout = ({
|
||||||
|
ASDN::SumScopeTimer t(_layoutComputationTotalTime, measureLayoutComputation);
|
||||||
|
[layoutSpec layoutThatFits:constrainedSize];
|
||||||
|
});
|
||||||
|
|
||||||
ASDisplayNodeAssertNotNil(layout, @"[ASLayoutSpec measureWithSizeRange:] should never return nil! %@, %@", self, layoutSpec);
|
ASDisplayNodeAssertNotNil(layout, @"[ASLayoutSpec measureWithSizeRange:] should never return nil! %@, %@", self, layoutSpec);
|
||||||
|
|
||||||
// Make sure layoutableObject of the root layout is `self`, so that the flattened layout will be structurally correct.
|
// Make sure layoutableObject of the root layout is `self`, so that the flattened layout will be structurally correct.
|
||||||
|
|||||||
@@ -171,9 +171,9 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo
|
|||||||
// performance measurement
|
// performance measurement
|
||||||
ASDisplayNodePerformanceMeasurementOptions _measurementOptions;
|
ASDisplayNodePerformanceMeasurementOptions _measurementOptions;
|
||||||
NSTimeInterval _layoutSpecTotalTime;
|
NSTimeInterval _layoutSpecTotalTime;
|
||||||
NSUInteger _layoutSpecNumberOfPasses;
|
NSInteger _layoutSpecNumberOfPasses;
|
||||||
NSTimeInterval _layoutGenerationTotalTime;
|
NSTimeInterval _layoutComputationTotalTime;
|
||||||
NSUInteger _layoutGenerationNumberOfPasses;
|
NSInteger _layoutComputationNumberOfPasses;
|
||||||
|
|
||||||
#if TIME_DISPLAYNODE_OPS
|
#if TIME_DISPLAYNODE_OPS
|
||||||
@public
|
@public
|
||||||
|
|||||||
@@ -42,11 +42,16 @@ namespace ASDN {
|
|||||||
struct SumScopeTimer {
|
struct SumScopeTimer {
|
||||||
NSTimeInterval begin;
|
NSTimeInterval begin;
|
||||||
NSTimeInterval &outT;
|
NSTimeInterval &outT;
|
||||||
SumScopeTimer(NSTimeInterval &outRef) : outT(outRef) {
|
BOOL enable;
|
||||||
begin = CACurrentMediaTime();
|
SumScopeTimer(NSTimeInterval &outRef, BOOL enable = YES) : outT(outRef), enable(enable) {
|
||||||
|
if (enable) {
|
||||||
|
begin = CACurrentMediaTime();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
~SumScopeTimer() {
|
~SumScopeTimer() {
|
||||||
outT += CACurrentMediaTime() - begin;
|
if (enable) {
|
||||||
|
outT += CACurrentMediaTime() - begin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user