[ 
https://issues.apache.org/jira/browse/WEEX-648?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16674874#comment-16674874
 ] 

ASF GitHub Bot commented on WEEX-648:
-------------------------------------

cxfeng1 closed pull request #1644: [WEEX-648][iOS]native batch for dom 
operations generating from JavaScript
URL: https://github.com/apache/incubator-weex/pull/1644
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.h 
b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.h
index 94eb39973e..d1a36edfe7 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.h
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.h
@@ -262,4 +262,18 @@ void WXPerformBlockSyncOnComponentThread(void 
(^block)(void));
  */
 - (void)enumerateComponentsUsingBlock:(void (^)(WXComponent *, BOOL 
*stop))block;
 
+#pragma mark batch mark
+
+/**
+ a start native batch tag for a group of UI operations, company with 
performBatchEnd
+ @see performBatchEnd
+ */
+- (void)performBatchBegin;
+
+/**
+ an end native batch tag for a group of UI operations, company with 
performBatchBegin
+ @see performBatchBegin
+ */
+- (void)performBatchEnd;
+
 @end
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm 
b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
index e22dc38d76..071580bffd 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
@@ -44,7 +44,7 @@
 static NSThread *WXComponentThread;
 
 #define WXAssertComponentExist(component)  WXAssert(component, @"component not 
exists")
-
+#define MAX_DROP_FRAME_FOR_BATCH   200
 
 @implementation WXComponentManager
 {
@@ -64,6 +64,7 @@ @implementation WXComponentManager
 
     pthread_mutex_t _propertyMutex;
     pthread_mutexattr_t _propertMutexAttr;
+    NSUInteger _syncUITaskCount;
 }
 
 + (instancetype)sharedManager
@@ -80,7 +81,7 @@ - (instancetype)initWithWeexInstance:(id)weexInstance
 {
     if (self = [self init]) {
         _weexInstance = weexInstance;
-        
+        _syncUITaskCount = 0;
         _indexDict = [NSMapTable strongToWeakObjectsMapTable];
         _fixedComponents = [NSMutableArray wx_mutableArrayUsingWeakReferences];
         _uiTaskQueue = [NSMutableArray array];
@@ -991,13 +992,42 @@ - (void) _printFlexComponentFrame:(WXComponent *)component
 
 - (void)_syncUITasks
 {
-    NSArray<dispatch_block_t> *blocks = _uiTaskQueue;
-    _uiTaskQueue = [NSMutableArray array];
-    dispatch_async(dispatch_get_main_queue(), ^{
-        for(dispatch_block_t block in blocks) {
-            block();
+    NSInteger mismatchBeginIndex = _uiTaskQueue.count;
+    for (NSInteger i = _uiTaskQueue.count - 1;i >= 0;i --) {
+        if (_uiTaskQueue[i] == WXPerformUITaskBatchEndBlock) {
+            _syncUITaskCount = 0;
+            // clear when find the matches for end and begin tag
+            break;
         }
-    });
+        if (_uiTaskQueue[i] == WXPerformUITaskBatchBeginBlock) {
+            mismatchBeginIndex = i;
+            break;
+        }
+    }
+    
+    if (mismatchBeginIndex == _uiTaskQueue.count) {
+        // here we get end tag or there are not begin and end directives
+    } else {
+        _syncUITaskCount ++;
+        // we only find begin tag but missing end tag,
+        if (_syncUITaskCount > (MAX_DROP_FRAME_FOR_BATCH)) {
+            // when the wait times come to MAX_DROP_FRAME_FOR_BATCH, we will 
pop all the stashed operations for user experience.
+            mismatchBeginIndex = _uiTaskQueue.count;
+            _syncUITaskCount = 0;
+        }
+    }
+    
+    if (mismatchBeginIndex > 0) {
+        NSArray<dispatch_block_t> *blocks = [_uiTaskQueue 
subarrayWithRange:NSMakeRange(0, mismatchBeginIndex)];
+        [_uiTaskQueue removeObjectsInRange:NSMakeRange(0, mismatchBeginIndex)];
+        if (blocks.count) {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                for(dispatch_block_t block in blocks) {
+                    block();
+                }
+            });
+        }
+    }
 }
 
 #pragma mark Fixed 
@@ -1051,6 +1081,27 @@ - (void)enumerateComponentsUsingBlock:(void 
(^)(WXComponent *, BOOL *stop))block
     }
 }
 
+static void (^WXPerformUITaskBatchBeginBlock)(void) = ^ () {
+#if DEBUG
+    WXLogDebug(@"directive BatchBeginBlock");
+#endif
+};
+static void (^WXPerformUITaskBatchEndBlock)(void) = ^ () {
+#if DEBUG
+    WXLogDebug(@"directive BatchEndBlock");
+#endif
+};
+
+- (void)performBatchBegin
+{
+    [self _addUITask:WXPerformUITaskBatchBeginBlock];
+}
+
+- (void)performBatchEnd
+{
+    [self _addUITask:WXPerformUITaskBatchEndBlock];
+}
+
 - (void)handleDisplayLink {
     [self _handleDisplayLink];
 }
diff --git a/ios/sdk/WeexSDK/Sources/Module/WXDomModule.m 
b/ios/sdk/WeexSDK/Sources/Module/WXDomModule.m
index f7f5dfe3e5..312d6f879e 100644
--- a/ios/sdk/WeexSDK/Sources/Module/WXDomModule.m
+++ b/ios/sdk/WeexSDK/Sources/Module/WXDomModule.m
@@ -55,6 +55,8 @@ @implementation WXDomModule
 WX_EXPORT_METHOD(@selector(addRule:rule:))
 WX_EXPORT_METHOD(@selector(getComponentRect:callback:))
 WX_EXPORT_METHOD(@selector(updateComponentData:componentData:callback:))
+WX_EXPORT_METHOD(@selector(beginBatchMark))
+WX_EXPORT_METHOD(@selector(endBatchMark))
 
 - (void)performBlockOnComponentManager:(void(^)(WXComponentManager *))block
 {
@@ -82,6 +84,20 @@ - (void)performSelectorOnRuleManager:(void(^)(void))block{
     });
 }
 
+- (void)beginBatchMark
+{
+    [self performBlockOnComponentManager:^(WXComponentManager *manager) {
+        [manager performBatchBegin];
+    }];
+}
+
+- (void)endBatchMark
+{
+    [self performBlockOnComponentManager:^(WXComponentManager * manager) {
+        [manager performBatchEnd];
+    }];
+}
+
 - (NSThread *)targetExecuteThread
 {
     return [WXComponentManager componentThread];


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> introduce native batch for dom operations generating from javaScript
> --------------------------------------------------------------------
>
>                 Key: WEEX-648
>                 URL: https://issues.apache.org/jira/browse/WEEX-648
>             Project: Weex
>          Issue Type: Improvement
>          Components: Android, iOS
>            Reporter: acton393
>            Assignee: acton393
>            Priority: Major
>
> We will introduce native batch for dom operations generating from javaScript
> wrap a series of dom operations with beginBatch and endBatch directives, when 
> every V-sync signal comes,  we ensure that the operations between beginBatch 
> and endBatch can be performed in current V-sync, this policy can drop frames 
> maybe, for our policy dropping frames, we only allow 20 frames at most.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to