Skip to content

Commit

Permalink
Use Maps instead of Objects for MessageQueue callbacks
Browse files Browse the repository at this point in the history
Summary:
This lead to exceeding the Object property count limit in Hermes:
```
Unhandled JS Exception: Property storage can't accommodate 254464 properties, js engine: hermes
```

Reviewed By: PeteTheHeat

Differential Revision: D16212572

fbshipit-source-id: 8fcedb55ebd1f8b289ec759ea1ad4e81cf903dfd
  • Loading branch information
sahrens authored and facebook-github-bot committed Jul 17, 2019
1 parent 87e0270 commit 8dcee62
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Libraries/BatchedBridge/MessageQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const DEBUG_INFO_LIMIT = 32;
class MessageQueue {
_lazyCallableModules: {[key: string]: (void) => Object};
_queue: [number[], number[], any[], number];
_successCallbacks: {[key: number]: ?Function};
_failureCallbacks: {[key: number]: ?Function};
_successCallbacks: Map<number, ?Function>;
_failureCallbacks: Map<number, ?Function>;
_callID: number;
_lastFlush: number;
_eventLoopStartTime: number;
Expand All @@ -56,8 +56,8 @@ class MessageQueue {
constructor() {
this._lazyCallableModules = {};
this._queue = [[], [], [], 0];
this._successCallbacks = {};
this._failureCallbacks = {};
this._successCallbacks = new Map();
this._failureCallbacks = new Map();
this._callID = 0;
this._lastFlush = 0;
this._eventLoopStartTime = Date.now();
Expand Down Expand Up @@ -217,8 +217,8 @@ class MessageQueue {
onFail && params.push(this._callID << 1);
// eslint-disable-next-line no-bitwise
onSucc && params.push((this._callID << 1) | 1);
this._successCallbacks[this._callID] = onSucc;
this._failureCallbacks[this._callID] = onFail;
this._successCallbacks.set(this._callID, onSucc);
this._failureCallbacks.set(this._callID, onFail);
}
if (__DEV__) {
global.nativeTraceBeginAsyncFlow &&
Expand Down Expand Up @@ -423,8 +423,8 @@ class MessageQueue {
// eslint-disable-next-line no-bitwise
const isSuccess = cbID & 1;
const callback = isSuccess
? this._successCallbacks[callID]
: this._failureCallbacks[callID];
? this._successCallbacks.get(callID)
: this._failureCallbacks.get(callID);

if (__DEV__) {
const debug = this._debugInfo[callID];
Expand Down Expand Up @@ -453,8 +453,8 @@ class MessageQueue {
return;
}

delete this._successCallbacks[callID];
delete this._failureCallbacks[callID];
this._successCallbacks.delete(callID);
this._failureCallbacks.delete(callID);
callback(...args);

if (__DEV__) {
Expand Down

0 comments on commit 8dcee62

Please sign in to comment.