Speed up Redux dev tools by disabling log serialization

Summary: Serializing the logs of the devices within Redux dev tools was causing Electron to crash due to it being out of memory. We can sanitize the state serialization by rewriting the device logs to <<DEVICE_LOGS>>. This fixes the issue and causes Electron to use less memory and CPU while in devlopment mode.

Reviewed By: jknoxville

Differential Revision: D16282673

fbshipit-source-id: abee6d167b23f24647e45f039a77ab60576ab3e6
This commit is contained in:
Benjamin Elo
2019-07-17 02:45:50 -07:00
committed by Facebook Github Bot
parent 9c96545bbd
commit ce93ecfcca
2 changed files with 44 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
export const stateSanitizer = state => {
let sanitizedState = state;
if (state.connections) {
if (state.connections.devices) {
const {devices} = state.connections;
sanitizedState = {
...sanitizedState,
connections: {
...state.connections,
devices: devices.map(device => {
return {
...device.toJSON(),
logs: '<<DEVICE_LOGS>>',
};
}),
},
};
}
if (state.connections.selectedDevice) {
const {selectedDevice} = state.connections;
sanitizedState = {
...sanitizedState,
connections: {
...sanitizedState.connections,
selectedDevice: {
...selectedDevice.toJSON(),
logs: '<<DEVICE_LOGS>>',
},
},
};
}
}
return sanitizedState;
};