Skip to content

Commit bb9169f

Browse files
authored
Merge pull request #74 from snyk/feat/add-memoization-to-depTreeToGraph
feat: add memoization when converting tree to graph
2 parents 56a66e3 + d842c25 commit bb9169f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/legacy/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ async function buildGraph(
7575
pkgName: string,
7676
eventLoopSpinner: EventLoopSpinner,
7777
isRoot = false,
78+
memoizationMap: Map<DepTree, string> = new Map(),
7879
): Promise<string> {
80+
if (memoizationMap.has(depTree)) {
81+
return memoizationMap.get(depTree)!;
82+
}
7983
const getNodeId = (
8084
name: string,
8185
version: string | undefined,
@@ -103,6 +107,8 @@ async function buildGraph(
103107
dep,
104108
depName,
105109
eventLoopSpinner,
110+
false,
111+
memoizationMap,
106112
);
107113

108114
const depPkg: types.PkgInfo = {
@@ -160,6 +166,7 @@ async function buildGraph(
160166
if (depNodesIds.length > 0 && eventLoopSpinner.isStarving()) {
161167
await eventLoopSpinner.spin();
162168
}
169+
memoizationMap.set(depTree, treeHash);
163170
return treeHash;
164171
}
165172

0 commit comments

Comments
 (0)