Change new Date() to Date.now() to save on date allocations
Summary: `new Date().getTime()` is equal to `Date.now()`. `Date.now()` avoids an allocation, which can save some GC time. This micro-optimization isn't worth it in most places, but since MessageQueue is one of the hottest pieces of JS in RN, it's worth it. Reviewed By: javache Differential Revision: D9972334 fbshipit-source-id: 05d78fd65304f0f27115d76b8b52db11a52c86a0
This commit is contained in:
parent
f409fd8d6e
commit
bbb2d9a5b3
|
@ -60,7 +60,7 @@ class MessageQueue {
|
|||
this._failureCallbacks = {};
|
||||
this._callID = 0;
|
||||
this._lastFlush = 0;
|
||||
this._eventLoopStartTime = new Date().getTime();
|
||||
this._eventLoopStartTime = Date.now();
|
||||
this._immediatesCallback = null;
|
||||
|
||||
if (__DEV__) {
|
||||
|
@ -141,7 +141,7 @@ class MessageQueue {
|
|||
}
|
||||
|
||||
getEventLoopRunningTime() {
|
||||
return new Date().getTime() - this._eventLoopStartTime;
|
||||
return Date.now() - this._eventLoopStartTime;
|
||||
}
|
||||
|
||||
registerCallableModule(name: string, module: Object) {
|
||||
|
@ -260,7 +260,7 @@ class MessageQueue {
|
|||
}
|
||||
this._queue[PARAMS].push(params);
|
||||
|
||||
const now = new Date().getTime();
|
||||
const now = Date.now();
|
||||
if (
|
||||
global.nativeFlushQueueImmediate &&
|
||||
now - this._lastFlush >= MIN_TIME_BETWEEN_FLUSHES_MS
|
||||
|
@ -340,7 +340,7 @@ class MessageQueue {
|
|||
}
|
||||
|
||||
__callFunction(module: string, method: string, args: any[]): any {
|
||||
this._lastFlush = new Date().getTime();
|
||||
this._lastFlush = Date.now();
|
||||
this._eventLoopStartTime = this._lastFlush;
|
||||
if (__DEV__ || this.__spy) {
|
||||
Systrace.beginEvent(`${module}.${method}(${stringifySafe(args)})`);
|
||||
|
@ -369,7 +369,7 @@ class MessageQueue {
|
|||
}
|
||||
|
||||
__invokeCallback(cbID: number, args: any[]) {
|
||||
this._lastFlush = new Date().getTime();
|
||||
this._lastFlush = Date.now();
|
||||
this._eventLoopStartTime = this._lastFlush;
|
||||
|
||||
// The rightmost bit of cbID indicates fail (0) or success (1), the other bits are the callID shifted left.
|
||||
|
|
Loading…
Reference in New Issue