From ce93ecfcca405dc48bbae85dbdb4d28996e78b28 Mon Sep 17 00:00:00 2001 From: Benjamin Elo Date: Wed, 17 Jul 2019 02:45:50 -0700 Subject: [PATCH] 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 <>. 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 --- src/init.js | 4 +++- src/utils/reduxDevToolsConfig.js | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/utils/reduxDevToolsConfig.js diff --git a/src/init.js b/src/init.js index a104d0dce..122eeba6b 100644 --- a/src/init.js +++ b/src/init.js @@ -19,13 +19,15 @@ import reducers from './reducers/index.js'; import dispatcher from './dispatcher/index.js'; import TooltipProvider from './ui/components/TooltipProvider.js'; import config from './utils/processConfig.js'; +import {stateSanitizer} from './utils/reduxDevToolsConfig.js'; import {initLauncherHooks} from './utils/launcher.js'; import initCrashReporter from './utils/electronCrashReporter'; const path = require('path'); const store = createStore( reducers, - window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(), + window.__REDUX_DEVTOOLS_EXTENSION__ && + window.__REDUX_DEVTOOLS_EXTENSION__({stateSanitizer}), ); const logger = initLogger(store); diff --git a/src/utils/reduxDevToolsConfig.js b/src/utils/reduxDevToolsConfig.js new file mode 100644 index 000000000..1ca88309e --- /dev/null +++ b/src/utils/reduxDevToolsConfig.js @@ -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: '<>', + }; + }), + }, + }; + } + if (state.connections.selectedDevice) { + const {selectedDevice} = state.connections; + sanitizedState = { + ...sanitizedState, + connections: { + ...sanitizedState.connections, + selectedDevice: { + ...selectedDevice.toJSON(), + logs: '<>', + }, + }, + }; + } + } + return sanitizedState; +};