Only call callImmediates once per batch

Reviewed By: AaaChiuuu

Differential Revision: D5163897

fbshipit-source-id: bcff70c4a6a6329b9ae771d9cad14876e3a40250
This commit is contained in:
Pieter De Baets 2017-06-02 08:16:04 -07:00 committed by Facebook Github Bot
parent c57d7eaf43
commit 07ee2fb90a
2 changed files with 10 additions and 8 deletions

View File

@ -99,7 +99,6 @@ class MessageQueue {
callFunctionReturnFlushedQueue(module: string, method: string, args: Array<any>) { callFunctionReturnFlushedQueue(module: string, method: string, args: Array<any>) {
this.__guard(() => { this.__guard(() => {
this.__callFunction(module, method, args); this.__callFunction(module, method, args);
this.__callImmediates();
}); });
return this.flushedQueue(); return this.flushedQueue();
@ -109,7 +108,6 @@ class MessageQueue {
let result; let result;
this.__guard(() => { this.__guard(() => {
result = this.__callFunction(module, method, args); result = this.__callFunction(module, method, args);
this.__callImmediates();
}); });
return [result, this.flushedQueue()]; return [result, this.flushedQueue()];
@ -118,14 +116,15 @@ class MessageQueue {
invokeCallbackAndReturnFlushedQueue(cbID: number, args: Array<any>) { invokeCallbackAndReturnFlushedQueue(cbID: number, args: Array<any>) {
this.__guard(() => { this.__guard(() => {
this.__invokeCallback(cbID, args); this.__invokeCallback(cbID, args);
this.__callImmediates();
}); });
return this.flushedQueue(); return this.flushedQueue();
} }
flushedQueue() { flushedQueue() {
this.__guard(() => {
this.__callImmediates(); this.__callImmediates();
});
const queue = this._queue; const queue = this._queue;
this._queue = [[], [], [], this._callID]; this._queue = [[], [], [], this._callID];
@ -220,7 +219,7 @@ class MessageQueue {
__callImmediates() { __callImmediates() {
Systrace.beginEvent('JSTimersExecution.callImmediates()'); Systrace.beginEvent('JSTimersExecution.callImmediates()');
this.__guard(() => JSTimersExecution.callImmediates()); JSTimersExecution.callImmediates();
Systrace.endEvent(); Systrace.endEvent();
} }

View File

@ -187,7 +187,9 @@ const JSTimersExecution = {
* more immediates are queued up (can be used as a condition a while loop). * more immediates are queued up (can be used as a condition a while loop).
*/ */
callImmediatesPass() { callImmediatesPass() {
if (__DEV__) {
Systrace.beginEvent('JSTimersExecution.callImmediatesPass()'); Systrace.beginEvent('JSTimersExecution.callImmediatesPass()');
}
// The main reason to extract a single pass is so that we can track // The main reason to extract a single pass is so that we can track
// in the system trace // in the system trace
@ -202,8 +204,9 @@ const JSTimersExecution = {
} }
} }
if (__DEV__) {
Systrace.endEvent(); Systrace.endEvent();
}
return JSTimersExecution.immediates.length > 0; return JSTimersExecution.immediates.length > 0;
}, },