-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[WEEX-648][iOS]native batch for dom operations generating from JavaScript #1644
Changes from 3 commits
2b1844e
9eec9f7
eb590d9
820c73e
319c0b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 operation , company with performBatchEnd | ||
@see performBatchEnd | ||
*/ | ||
- (void)performBatchBegin; | ||
|
||
/** | ||
an end native batch tag for a group of UI operation, company with performBatchBegin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. operation -> operations |
||
@see performBatchBegin | ||
*/ | ||
- (void)performBatchEnd; | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ | |
static NSThread *WXComponentThread; | ||
|
||
#define WXAssertComponentExist(component) WXAssert(component, @"component not exists") | ||
|
||
#define MAX_DROP_FRAME_FOR_BATCH 200 | ||
|
||
@implementation WXComponentManager | ||
{ | ||
|
@@ -991,8 +991,38 @@ - (void) _printFlexComponentFrame:(WXComponent *)component | |
|
||
- (void)_syncUITasks | ||
{ | ||
NSArray<dispatch_block_t> *blocks = _uiTaskQueue; | ||
_uiTaskQueue = [NSMutableArray array]; | ||
static NSInteger _syncUITaskCount = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _syncUITaskCount不能声明为static,不同的instance有不同的componentManager不能共用一个变量。 |
||
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; | ||
} | ||
} | ||
|
||
NSArray<dispatch_block_t> *blocks = nil; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blocks声明放到下面if (mismatchBeginIndex > 0)里吧 |
||
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 operation for user experience. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stashed operation -> stashed operations |
||
mismatchBeginIndex = _uiTaskQueue.count; | ||
_syncUITaskCount = 0; | ||
} | ||
} | ||
|
||
if (mismatchBeginIndex > 0) { | ||
blocks = [_uiTaskQueue subarrayWithRange:NSMakeRange(0, mismatchBeginIndex)]; | ||
[_uiTaskQueue removeObjectsInRange:NSMakeRange(0, blocks.count)]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blocks.count换成mismatchBeginIndex吧,看起来更对称一些,而且减少一次blocks.count调用。 |
||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 把下面的dispatch_async也放到if (mismatchBeginIndex > 0)这个if里面吧,空任务的时候减少一次给main提交block。 |
||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
for(dispatch_block_t block in blocks) { | ||
block(); | ||
|
@@ -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]; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉多余的空格,operation -> operations