This is an automated email from the ASF dual-hosted git repository.

zshshr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git


The following commit(s) were added to refs/heads/master by this push:
     new fdb024b  [iOS] Add display link task and report vdom, component count 
to apm by task avoiding too much invocations. Hide header of 
WXDisplayLinkManager.
fdb024b is described below

commit fdb024b56ddc3f25aef9ae14dfb9617bffc7ee17
Author: wqyfavor <qianyuan....@taobao.com>
AuthorDate: Thu Jan 3 16:41:15 2019 +0800

    [iOS] Add display link task and report vdom, component count to apm by task 
avoiding too much invocations. Hide header of WXDisplayLinkManager.
---
 ios/sdk/WeexSDK.xcodeproj/project.pbxproj          |  8 +-
 .../WeexSDK/Sources/Manager/WXComponentManager.h   |  3 +-
 .../WeexSDK/Sources/Manager/WXComponentManager.mm  | 92 ++++++++++++++++++++--
 ios/sdk/WeexSDK/Sources/WeexSDK.h                  |  1 -
 4 files changed, 91 insertions(+), 13 deletions(-)

diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj 
b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
index d7c4e24..ba8efa8 100644
--- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
+++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
@@ -90,9 +90,9 @@
                4505D12C219B216D0083A1A2 /* class_window.cc in Sources */ = 
{isa = PBXBuildFile; fileRef = 98399A8321916A9700D83CCE /* class_window.cc */; 
};
                4505D12D219B21760083A1A2 /* class_window.h in Headers */ = {isa 
= PBXBuildFile; fileRef = 98399A8521916A9700D83CCE /* class_window.h */; };
                4505D12E219B22630083A1A2 /* op_code.cc in Sources */ = {isa = 
PBXBuildFile; fileRef = 98399A8A21916A9800D83CCE /* op_code.cc */; };
-               4532670A213FC84A00DAA620 /* WXDisplayLinkManager.h in Headers 
*/ = {isa = PBXBuildFile; fileRef = 45326708213FC84900DAA620 /* 
WXDisplayLinkManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
+               4532670A213FC84A00DAA620 /* WXDisplayLinkManager.h in Headers 
*/ = {isa = PBXBuildFile; fileRef = 45326708213FC84900DAA620 /* 
WXDisplayLinkManager.h */; };
                4532670B213FC84A00DAA620 /* WXDisplayLinkManager.m in Sources 
*/ = {isa = PBXBuildFile; fileRef = 45326709213FC84900DAA620 /* 
WXDisplayLinkManager.m */; };
-               4532670C213FCF2300DAA620 /* WXDisplayLinkManager.h in Headers 
*/ = {isa = PBXBuildFile; fileRef = 45326708213FC84900DAA620 /* 
WXDisplayLinkManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
+               4532670C213FCF2300DAA620 /* WXDisplayLinkManager.h in Headers 
*/ = {isa = PBXBuildFile; fileRef = 45326708213FC84900DAA620 /* 
WXDisplayLinkManager.h */; };
                4532670D213FCFB400DAA620 /* WXDisplayLinkManager.m in Sources 
*/ = {isa = PBXBuildFile; fileRef = 45326709213FC84900DAA620 /* 
WXDisplayLinkManager.m */; };
                453267142140E38900DAA620 /* vcomponent.h in Headers */ = {isa = 
PBXBuildFile; fileRef = 453267122140E38900DAA620 /* vcomponent.h */; };
                453267152140E38900DAA620 /* vcomponent.cc in Sources */ = {isa 
= PBXBuildFile; fileRef = 453267132140E38900DAA620 /* vcomponent.cc */; };
@@ -2750,7 +2750,6 @@
                        buildActionMask = 2147483647;
                        files = (
                                7715EB6221A69DD9001F1108 /* WXRichText.h in 
Headers */,
-                               4532670A213FC84A00DAA620 /* 
WXDisplayLinkManager.h in Headers */,
                                B8D66C1B21255730003960BD /* style.h in Headers 
*/,
                                B8D66C2321255730003960BD /* layout.h in Headers 
*/,
                                B8D66C2521255730003960BD /* flex_enum.h in 
Headers */,
@@ -2811,6 +2810,7 @@
                                B8D66C3121255730003960BD /* 
render_action_appendtree_createfinish.h in Headers */,
                                B8F2C6EE2133A83C00635B37 /* class.h in Headers 
*/,
                                B8D66C7F21255730003960BD /* 
render_scroller_factory.h in Headers */,
+                               4532670A213FC84A00DAA620 /* 
WXDisplayLinkManager.h in Headers */,
                                74A4BA5B1CABBBD000195969 /* WXDebugTool.h in 
Headers */,
                                2A837AB41CD9DE9200AEDF03 /* 
WXLoadingIndicator.h in Headers */,
                                45E0B4C121CB7B82005D1B3B /* WXConvertUtility.h 
in Headers */,
@@ -3043,7 +3043,6 @@
                        buildActionMask = 2147483647;
                        files = (
                                7715EB6321A69DD9001F1108 /* WXRichText.h in 
Headers */,
-                               4532670C213FCF2300DAA620 /* 
WXDisplayLinkManager.h in Headers */,
                                B8D66C1C21255730003960BD /* style.h in Headers 
*/,
                                B8D66C2421255730003960BD /* layout.h in Headers 
*/,
                                B8D66C2621255730003960BD /* flex_enum.h in 
Headers */,
@@ -3103,6 +3102,7 @@
                                DCA445AC1EFA574A00D0CFA8 /* WXNetworkProtocol.h 
in Headers */,
                                DCA445C31EFA57DC00D0CFA8 /* 
WXAppMonitorProtocol.h in Headers */,
                                B8D66BC42125572F003960BD /* 
vnode_render_context.h in Headers */,
+                               4532670C213FCF2300DAA620 /* 
WXDisplayLinkManager.h in Headers */,
                                DCA445AF1EFA575D00D0CFA8 /* WXModuleProtocol.h 
in Headers */,
                                4547FD102153932A00E79971 /* 
js_common_function.h in Headers */,
                                45E0B4C221CB7B9C005D1B3B /* WXConvertUtility.h 
in Headers */,
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.h 
b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.h
index 2fa258e..63678c2 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.h
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.h
@@ -19,7 +19,6 @@
 
 #import <CoreGraphics/CoreGraphics.h>
 #import <Foundation/Foundation.h>
-#import "WXDisplayLinkManager.h"
 
 @class WXBridgeMethod;
 @class WXSDKInstance;
@@ -36,7 +35,7 @@ void WXPerformBlockSyncOnComponentThread(void (^block)(void));
 }
 #endif
 
-@interface WXComponentManager : NSObject <WXDisplayLinkClient>
+@interface WXComponentManager : NSObject
 
 @property (nonatomic, readonly, weak) WXSDKInstance *weexInstance;
 @property (nonatomic, readonly, assign) BOOL isValid;
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm 
b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
index 6edbae1..aef0292 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
@@ -41,12 +41,37 @@
 #import "WXCoreBridge.h"
 #import "WXComponent_performance.h"
 #import "WXAnalyzerCenter.h"
+#import "WXDisplayLinkManager.h"
 
 static NSThread *WXComponentThread;
 
+/* Task scheduled on component thread and triggered every N display link ticks.
+ If display link is stopped, the tasks are also suspended. */
+@interface WXComponentThreadTickTask : NSObject
+
+@property (nonatomic, assign) NSUInteger displayTickCount; // Triggered every 
N display link ticks
+@property (nonatomic, copy) dispatch_block_t block;
+
+@end
+
+@implementation WXComponentThreadTickTask
+
++ (instancetype)taskWithBlock:(dispatch_block_t)block 
tickCount:(NSUInteger)tickCount
+{
+    WXComponentThreadTickTask* task = [[WXComponentThreadTickTask alloc] init];
+    task.displayTickCount = tickCount;
+    task.block = block;
+    return task;
+}
+
+@end
+
 #define WXAssertComponentExist(component)  WXAssert(component, @"component not 
exists")
 #define MAX_DROP_FRAME_FOR_BATCH   200
 
+@interface WXComponentManager () <WXDisplayLinkClient>
+@end
+
 @implementation WXComponentManager
 {
     __weak WXSDKInstance *_weexInstance;
@@ -59,6 +84,15 @@ static NSThread *WXComponentThread;
     NSMapTable<NSString *, WXComponent *> *_indexDict;
     NSMutableArray<dispatch_block_t> *_uiTaskQueue;
     NSMutableDictionary *_uiPrerenderTaskQueue;
+    
+    NSUInteger _displayTick;
+    NSMutableArray<WXComponentThreadTickTask*> *_displayTaskQueue;
+    
+    // vdom depth and component count statistics
+    NSUInteger _maxVdomDepth;
+    NSUInteger _maxVdomDepthReported;
+    NSUInteger _maxComponentCount;
+    NSUInteger _maxComponentCountReported;
 
     WXComponent *_rootComponent;
     NSMutableArray *_fixedComponents;
@@ -86,6 +120,7 @@ static NSThread *WXComponentThread;
         _indexDict = [NSMapTable strongToWeakObjectsMapTable];
         _fixedComponents = [NSMutableArray wx_mutableArrayUsingWeakReferences];
         _uiTaskQueue = [NSMutableArray array];
+        _displayTaskQueue = [NSMutableArray array];
         _isValid = YES;
         pthread_mutexattr_init(&_propertMutexAttr);
         pthread_mutexattr_settype(&_propertMutexAttr, PTHREAD_MUTEX_RECURSIVE);
@@ -93,6 +128,7 @@ static NSThread *WXComponentThread;
         
         WXPerformBlockOnComponentThread(^{
             // We should ensure that [WXDisplayLinkManager sharedInstance] is 
only invoked in component thread.
+            [self _addVdomAndComponentCountTask];
             [self _startDisplayLink];
         });
     }
@@ -313,8 +349,11 @@ static NSThread *WXComponentThread;
         component->_lazyCreateView = YES;
     }
     
+    // update max vdom depth & component count, and will update apm data on 
next display task.
     [self recordMaximumVirtualDom:component];
-    [component.weexInstance.apmInstance 
updateMaxStats:KEY_PAGE_STATS_MAX_COMPONENT_NUM curMaxValue:[_indexDict count]];
+    if ([_indexDict count] > _maxComponentCount) {
+        _maxComponentCount = [_indexDict count];
+    }
     
     if (!component->_isTemplate) {
         __weak typeof(self) weakSelf = self;
@@ -416,12 +455,14 @@ static NSThread *WXComponentThread;
         maxDeep++;
         component = component.supercomponent;
     }
-    [self.weexInstance.apmInstance updateMaxStats:KEY_PAGE_STATS_MAX_DEEP_DOM 
curMaxValue:maxDeep];
-    if(maxDeep > [self weexInstance].performance.maxVdomDeep)
-    {
+    
+    if (maxDeep > [self weexInstance].performance.maxVdomDeep) {
         [self weexInstance].performance.maxVdomDeep = maxDeep;
     }
-   
+    
+    if (maxDeep > _maxVdomDepth) {
+        _maxVdomDepth = maxDeep;
+    }
 }
 
 - (void)_checkFixedSubcomponentToRemove:(WXComponent *)component
@@ -928,12 +969,32 @@ static NSThread *WXComponentThread;
     return _isValid;
 }
 
-#pragma mark Layout Batch
+#pragma mark Display link task
+
+- (void)_addVdomAndComponentCountTask
+{
+    __weak WXComponentManager* wself = self;
+    [_displayTaskQueue addObject:[WXComponentThreadTickTask taskWithBlock:^{
+        __strong WXComponentManager* sself = wself;
+        if (sself) {
+            if (sself->_maxComponentCount != 
sself->_maxComponentCountReported) {
+                [sself.weexInstance.apmInstance 
updateMaxStats:KEY_PAGE_STATS_MAX_COMPONENT_NUM 
curMaxValue:sself->_maxComponentCount];
+                sself->_maxComponentCountReported = sself->_maxComponentCount;
+            }
+            
+            if (sself->_maxVdomDepth != sself->_maxVdomDepthReported) {
+                [sself.weexInstance.apmInstance 
updateMaxStats:KEY_PAGE_STATS_MAX_DEEP_DOM curMaxValue:sself->_maxVdomDepth];
+                sself->_maxVdomDepthReported = sself->_maxVdomDepth;
+            }
+        }
+    } tickCount:30 /* triggered about every 500ms */]];
+}
 
 - (void)_startDisplayLink
 {
     WXAssertComponentThread();
     [[WXDisplayLinkManager sharedInstance] registerDisplayClient:self];
+    _displayTick = 0;
 }
 
 - (void)_stopDisplayLink
@@ -946,12 +1007,14 @@ static NSThread *WXComponentThread;
 {
     WXAssertComponentThread();
     _suspend = YES;
+    [self _executeDisplayTask:YES]; // on suspend, executes every task once
 }
 
 - (void)_awakeDisplayLink
 {
     WXAssertComponentThread();
     _suspend = NO;
+    _displayTick = 0;
 }
 
 - (void)_handleDisplayLink
@@ -959,6 +1022,23 @@ static NSThread *WXComponentThread;
     WXAssertComponentThread();
     
     [self _layoutAndSyncUI];
+    
+    if (!_suspend) {
+        // execute tasks in _displayTaskQueue
+        _displayTick ++;
+        [self _executeDisplayTask:NO];
+    }
+}
+
+- (void)_executeDisplayTask:(BOOL)onSuspend
+{
+    for (WXComponentThreadTickTask* task in _displayTaskQueue) {
+        if (onSuspend || (_displayTick % task.displayTickCount == 0)) {
+            if (task.block) {
+                task.block();
+            }
+        }
+    }
 }
 
 - (void)_layoutAndSyncUI
diff --git a/ios/sdk/WeexSDK/Sources/WeexSDK.h 
b/ios/sdk/WeexSDK/Sources/WeexSDK.h
index 4389bf4..e29bdc1 100644
--- a/ios/sdk/WeexSDK/Sources/WeexSDK.h
+++ b/ios/sdk/WeexSDK/Sources/WeexSDK.h
@@ -60,7 +60,6 @@
 #import "WXExceptionUtils.h"
 #import "WXEventModuleProtocol.h"
 #import "WXErrorView.h"
-#import "WXDisplayLinkManager.h"
 #import "WXDefine.h"
 #import "WXDebugTool.h"
 #import "WXConvert.h"

Reply via email to