fix: out-of-memory error during peers resolution (#7149)

This commit is contained in:
Zoltan Kochan
2023-09-28 21:40:03 +03:00
committed by GitHub
parent a5fff1cf51
commit b0afd78339
2 changed files with 13 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---
Optimize peers resolution to avoid out-of-memory exceptions in some rare cases, when there are too many circular dependencies and peer dependencies [#7149](https://github.com/pnpm/pnpm/pull/7149).

View File

@@ -9,6 +9,7 @@ import type {
} from '@pnpm/types'
import { depPathToFilename, createPeersFolderSuffix } from '@pnpm/dependency-path'
import mapValues from 'ramda/src/map'
import partition from 'ramda/src/partition'
import pick from 'ramda/src/pick'
import scan from 'ramda/src/scan'
import {
@@ -497,7 +498,12 @@ function resolvePeersOfChildren<T extends PartialResolvedPackage> (
const allResolvedPeers = new Map<string, string>()
const allMissingPeers = new Set<string>()
for (const childNodeId of Object.values(children)) {
// 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.
const [repeated, notRepeated] = partition(([alias]) => parentPkgs[alias] != null, Object.entries(children))
// Resolving non-repeated nodes before repeated nodes proved to be slightly faster.
for (const [, childNodeId] of [...notRepeated, ...repeated]) {
const { resolvedPeers, missingPeers } = resolvePeersOfNode(childNodeId, parentPkgs, ctx)
for (const [k, v] of resolvedPeers) {
allResolvedPeers.set(k, v)