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

This commit is contained in:
Zoltan Kochan
2024-05-07 13:37:47 +02:00
committed by GitHub
parent 43b6bb7ce3
commit 2cb67d7294
2 changed files with 39 additions and 21 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---
Improve the performance of the peers resolution stage by utilizing more cache [#8058](https://github.com/pnpm/pnpm/pull/8058).

View File

@@ -350,28 +350,40 @@ async function resolvePeersOfNode<T extends PartialResolvedPackage> (
}))
)
)
const hit = ctx.peersCache.get(resolvedPackage.depPath)?.find((cache) => {
for (const [name, cachedNodeId] of cache.resolvedPeers) {
const parentPkgNodeId = parentPkgs[name]?.nodeId
if (!parentPkgNodeId || !cachedNodeId) return false
if (parentPkgNodeId === cachedNodeId) continue
if (
ctx.pathsByNodeId.has(cachedNodeId) &&
ctx.pathsByNodeId.get(cachedNodeId) === ctx.pathsByNodeId.get(parentPkgNodeId)
) continue
if (!ctx.dependenciesTree.has(parentPkgNodeId) && parentPkgNodeId.startsWith('link:')) {
return false
const hit = findHit(resolvedPackage.depPath)
function findHit (depPath: string, pendingCacheSearches: string[] = []) {
const cacheItems = ctx.peersCache.get(depPath)
if (!cacheItems) return undefined
const newPendingCacheSearches = [...pendingCacheSearches, depPath]
return cacheItems.find((cache) => {
for (const [name, cachedNodeId] of cache.resolvedPeers) {
const parentPkgNodeId = parentPkgs[name]?.nodeId
if (!parentPkgNodeId || !cachedNodeId) return false
if (parentPkgNodeId === cachedNodeId) continue
if (
ctx.pathsByNodeId.has(cachedNodeId) &&
ctx.pathsByNodeId.get(cachedNodeId) === ctx.pathsByNodeId.get(parentPkgNodeId)
) continue
if (!ctx.dependenciesTree.has(parentPkgNodeId) && parentPkgNodeId.startsWith('link:')) {
return false
}
const parentDepPath = (ctx.dependenciesTree.get(parentPkgNodeId)!.resolvedPackage as T).depPath
if (!ctx.purePkgs.has(parentDepPath)) {
if (
newPendingCacheSearches.includes(parentDepPath) ||
findHit(parentDepPath, newPendingCacheSearches)
) continue
return false
}
const cachedDepPath = (ctx.dependenciesTree.get(cachedNodeId)!.resolvedPackage as T).depPath
if (parentDepPath !== cachedDepPath) return false
}
const parentDepPath = (ctx.dependenciesTree.get(parentPkgNodeId)!.resolvedPackage as T).depPath
if (!ctx.purePkgs.has(parentDepPath)) return false
const cachedDepPath = (ctx.dependenciesTree.get(cachedNodeId)!.resolvedPackage as T).depPath
if (parentDepPath !== cachedDepPath) return false
}
for (const missingPeer of cache.missingPeers) {
if (parentPkgs[missingPeer]) return false
}
return true
})
for (const missingPeer of cache.missingPeers) {
if (parentPkgs[missingPeer]) return false
}
return true
})
}
if (hit != null) {
return {
missingPeers: hit.missingPeers,