fix: reduce memory usage during peers resolution (#8106)

ref #8072
This commit is contained in:
Zoltan Kochan
2024-05-21 13:53:19 +02:00
committed by GitHub
parent 771d7a25c6
commit 471ee65532
2 changed files with 9 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---
Reduce memory usage by peer dependencies resolution [#8072](https://github.com/pnpm/pnpm/issues/8072).

View File

@@ -738,9 +738,10 @@ async function resolvePeersOfChildren<T extends PartialResolvedPackage> (
const allMissingPeers = new Set<string>()
// Partition children based on whether they're repeated in parentPkgs.
// This impacts the efficiency of graph traversal and prevents potential out-of-memory errors.mes can even lead to out-of-memory exceptions.
// This impacts the efficiency of graph traversal and prevents potential out-of-memory errors.
// We check repeated first as the peers resolution of those probably are cached already.
const [repeated, notRepeated] = partition(([alias]) => parentPkgs[alias] != null, Object.entries(children))
const nodeIds = Array.from(new Set([...notRepeated, ...repeated].map(([, nodeId]) => nodeId)))
const nodeIds = Array.from(new Set([...repeated, ...notRepeated].map(([, nodeId]) => nodeId)))
for (const nodeId of nodeIds) {
if (!ctx.pathsByNodeIdPromises.has(nodeId)) {