Skip to content

Commit

Permalink
Only call callImmediates once per batch
Browse files Browse the repository at this point in the history
Reviewed By: AaaChiuuu

Differential Revision: D5163897

fbshipit-source-id: bcff70c4a6a6329b9ae771d9cad14876e3a40250
  • Loading branch information
javache authored and facebook-github-bot committed Jun 2, 2017
1 parent c57d7ea commit 07ee2fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 4 additions & 5 deletions Libraries/BatchedBridge/MessageQueue.js
Expand Up @@ -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();
Expand All @@ -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()];
Expand All @@ -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.__callImmediates(); this.__guard(() => {
this.__callImmediates();
});


const queue = this._queue; const queue = this._queue;
this._queue = [[], [], [], this._callID]; this._queue = [[], [], [], this._callID];
Expand Down Expand Up @@ -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();
} }


Expand Down
9 changes: 6 additions & 3 deletions Libraries/Core/Timers/JSTimersExecution.js
Expand Up @@ -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() {
Systrace.beginEvent('JSTimersExecution.callImmediatesPass()'); if (__DEV__) {
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
Expand All @@ -202,8 +204,9 @@ const JSTimersExecution = {
} }
} }


Systrace.endEvent(); if (__DEV__) {

Systrace.endEvent();
}
return JSTimersExecution.immediates.length > 0; return JSTimersExecution.immediates.length > 0;
}, },


Expand Down

0 comments on commit 07ee2fb

Please sign in to comment.