JSON.stringify over custom serializer

Summary: This diff calls JSON.stringify on the final export object instead of the custom serializer. As the custom serializer is slower, because it has to check for different types on its children before serializing it. Which adds to the complexity. The time gain which we get is 3x, that is with this change the export is 3 times faster. We required custom serializer, because the logs had `Date` which is not serializable. So that is being taken care while importing it.

Reviewed By: jknoxville

Differential Revision: D18171202

fbshipit-source-id: cd1b59b74dabb4c35a032dc7b54f183a68e37823
This commit is contained in:
Pritesh Nandgaonkar
2019-10-29 13:41:44 -07:00
committed by Facebook Github Bot
parent f49745448c
commit e73381a85c

View File

@@ -27,7 +27,6 @@ import {default as Client} from '../Client';
import fs from 'fs';
import uuid from 'uuid';
import {remote, OpenDialogOptions} from 'electron';
import {serialize, deserialize} from './serialization';
import {readCurrentRevision} from './packageMetadata';
import {tryCatchReportPlatformFailures} from './metrics';
import {promisify} from 'util';
@@ -509,11 +508,7 @@ export function exportStore(
);
if (exportData != null) {
statusUpdate && statusUpdate('Serializing Flipper data...');
const serializedString = await serialize(
exportData,
idler,
statusUpdate,
);
const serializedString = JSON.stringify(exportData);
if (serializedString.length <= 0) {
reject(new Error('Serialize function returned empty string'));
}
@@ -547,7 +542,7 @@ export const exportStoreToFile = (
export function importDataToStore(data: string, store: Store) {
getLogger().track('usage', IMPORT_FLIPPER_TRACE_EVENT);
const json: ExportType = deserialize(data);
const json: ExportType = JSON.parse(data);
const {device, clients} = json;
if (device == null) {
return;
@@ -558,7 +553,11 @@ export function importDataToStore(data: string, store: Store) {
deviceType,
title,
os,
logs ? logs : [],
logs
? logs.map(l => {
return {...l, date: new Date(l.date)};
})
: [],
);
const devices = store.getState().connections.devices;
const matchedDevices = devices.filter(