From e73381a85cc485ca2c8bd3f6eb886c0045911b13 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Tue, 29 Oct 2019 13:41:44 -0700 Subject: [PATCH] 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 --- src/utils/exportData.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/utils/exportData.tsx b/src/utils/exportData.tsx index 7a213bee6..679600e8e 100644 --- a/src/utils/exportData.tsx +++ b/src/utils/exportData.tsx @@ -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(