Skip to content

Commit

Permalink
flow
Browse files Browse the repository at this point in the history
  • Loading branch information
AGawrys committed Nov 3, 2023
1 parent 8df5a96 commit 75527f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
9 changes: 5 additions & 4 deletions packages/dev/query/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<string | number>> = [];
table.push([
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -943,7 +944,7 @@ export function run(input: string[]) {
[
'inspectCache',
{
help: 'args: <>',
help: 'Cache Information',
action: inspectCache,
},
],
Expand Down
55 changes: 22 additions & 33 deletions packages/dev/query/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export function loadGraphs(cacheDir: string): {|

let cacheInfo: Map<string, Array<string | number>> = new Map();
let timeToDeserialize = 0;
let timeToDeserialize_AssetGraph = 0;
let timeToDeserialize_BundleGraph = 0;

let requestTracker;
for (let f of filesBySizeAndModifiedTime()) {
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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;
}

0 comments on commit 75527f4

Please sign in to comment.