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:
committed by
Facebook Github Bot
parent
9c96545bbd
commit
ce93ecfcca
@@ -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);
|
||||
|
||||
41
src/utils/reduxDevToolsConfig.js
Normal file
41
src/utils/reduxDevToolsConfig.js
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user