From 75527f4bee124c2ab253bf2359e418111d2d0970 Mon Sep 17 00:00:00 2001 From: Agnieszka Gawrys Date: Thu, 2 Nov 2023 18:26:11 -0700 Subject: [PATCH] flow --- packages/dev/query/src/cli.js | 9 +++--- packages/dev/query/src/index.js | 55 +++++++++++++-------------------- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/packages/dev/query/src/cli.js b/packages/dev/query/src/cli.js index 571cd975929..78ac12bc766 100644 --- a/packages/dev/query/src/cli.js +++ b/packages/dev/query/src/cli.js @@ -591,7 +591,8 @@ export function run(input: string[]) { return entryBundleGroup; } - function inspectCache() { + // eslint-disable-next-line no-unused-vars + function inspectCache(_) { // displays sizing of various entries of the cache let table: Array> = []; table.push([ @@ -636,11 +637,11 @@ export function run(input: string[]) { let bundlegraph_st = Date.now(); serialize(bundleGraph); bundlegraph_st = Date.now() - bundlegraph_st; - serializeTime.set('BundleGraph', bundlegraph_st); + serializeTime.set('bundle_graph_request', bundlegraph_st); let assetgraph_st = Date.now(); serialize(assetGraph); assetgraph_st = Date.now() - assetgraph_st; - serializeTime.set('AssetGraph', assetgraph_st); + serializeTime.set('asset_graph_request', assetgraph_st); return serializeTime; } @@ -943,7 +944,7 @@ export function run(input: string[]) { [ 'inspectCache', { - help: 'args: <>', + help: 'Cache Information', action: inspectCache, }, ], diff --git a/packages/dev/query/src/index.js b/packages/dev/query/src/index.js index a8e9a805749..1223ab3b259 100644 --- a/packages/dev/query/src/index.js +++ b/packages/dev/query/src/index.js @@ -40,8 +40,6 @@ export function loadGraphs(cacheDir: string): {| let cacheInfo: Map> = new Map(); let timeToDeserialize = 0; - let timeToDeserialize_AssetGraph = 0; - let timeToDeserialize_BundleGraph = 0; let requestTracker; for (let f of filesBySizeAndModifiedTime()) { @@ -86,7 +84,8 @@ export function loadGraphs(cacheDir: string): {| // Load graphs by finding the main subrequests and loading their results let assetGraph, bundleGraph, bundleInfo; - + cacheInfo.set('bundle_graph_request', []); + cacheInfo.set('asset_graph_request', []); invariant(requestTracker); let buildRequestId = requestTracker.graph.getNodeIdByContentKey( 'parcel_build_request', @@ -104,45 +103,29 @@ export function loadGraphs(cacheDir: string): {| n => n.type === 'request' && n.value.type === 'bundle_graph_request', ); if (bundleGraphRequestNode != null) { - let bundleGraphBytes = Buffer.byteLength( - fs.readFileSync( - path.join( - cacheDir, - nullthrows(bundleGraphRequestNode.value.resultCacheKey), - ), - ), - ); - cacheInfo.set('BundleGraph', [bundleGraphBytes]); - let date = Date.now(); bundleGraph = BundleGraph.deserialize( - loadLargeBlobRequestRequestSync(cacheDir, bundleGraphRequestNode) - .bundleGraph.value, + loadLargeBlobRequestRequestSync( + cacheDir, + bundleGraphRequestNode, + cacheInfo, + ).bundleGraph.value, ); - timeToDeserialize_BundleGraph = Date.now() - date; let assetGraphRequest = getSubRequests( requestTracker.graph.getNodeIdByContentKey(bundleGraphRequestNode.id), ).find(n => n.type === 'request' && n.value.type === 'asset_graph_request'); if (assetGraphRequest != null) { - let assetgraphbytes = Buffer.byteLength( - fs.readFileSync( - path.join( - cacheDir, - nullthrows(assetGraphRequest.value.resultCacheKey), - ), - ), + invariant( + assetGraphRequest.value != null && + typeof assetGraphRequest.value != 'string', ); - cacheInfo.set('AssetGraph', [assetgraphbytes]); - date = Date.now(); + assetGraph = AssetGraph.deserialize( - loadLargeBlobRequestRequestSync(cacheDir, assetGraphRequest).assetGraph - .value, + loadLargeBlobRequestRequestSync(cacheDir, assetGraphRequest, cacheInfo) + .assetGraph.value, ); - timeToDeserialize_AssetGraph = Date.now() - date; } } - cacheInfo.get('BundleGraph')?.push(timeToDeserialize_BundleGraph); - cacheInfo.get('AssetGraph')?.push(timeToDeserialize_AssetGraph); cacheInfo.get('RequestGraph')?.push(timeToDeserialize); let writeBundlesRequest = buildRequestSubRequests.find( n => n.type === 'request' && n.value.type === 'write_bundles_request', @@ -159,9 +142,15 @@ export function loadGraphs(cacheDir: string): {| return {assetGraph, bundleGraph, requestTracker, bundleInfo, cacheInfo}; } -function loadLargeBlobRequestRequestSync(cacheDir, node) { +function loadLargeBlobRequestRequestSync(cacheDir, node, cacheInfo) { invariant(node.type === 'request'); - return v8.deserialize( - fs.readFileSync(path.join(cacheDir, nullthrows(node.value.resultCacheKey))), + let TTD = Date.now(); + let cachedFile = fs.readFileSync( + path.join(cacheDir, nullthrows(node.value.resultCacheKey)), ); + cacheInfo.get(node.value.type)?.push(cachedFile.byteLength); + let result = v8.deserialize(cachedFile); + TTD = Date.now() - TTD; + cacheInfo.get(node.value.type)?.push(TTD); + return result; }