perf(resolve-dependencies): avoid copying preferredVersions object (#6735)

replacing object spread with a prototype chain,
avoiding extra memory allocations in resolveDependencies

this becomes noticeable on relatively large monorepo(~2k packages)
reducing memory usage and making it slightly faster

1. allowing to complete `pnpm install` without `--max_old_space_size=8192`
   (it is noticeably slower, but at least works)
2. prevents OOM issue with `auto-install-peers=true`
   (this is crashing otherwise no matter `max_old_space_size`)
This commit is contained in:
Bogdan Savluk
2023-06-30 01:00:15 +02:00
committed by GitHub
parent a950aa1483
commit e9684b5595
2 changed files with 6 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/resolve-dependencies": patch
---
replacing object copying with a prototype chain, avoiding extra memory allocations in resolveDependencies function

View File

@@ -522,7 +522,7 @@ export async function resolveDependencies (
postponedPeersResolutionQueue.push(postponedPeersResolution)
}
})
const newPreferredVersions = { ...preferredVersions }
const newPreferredVersions = Object.create(preferredVersions) as PreferredVersions
const currentParentPkgAliases: Record<string, PkgAddress | true> = {}
for (const pkgAddress of pkgAddresses) {
if (currentParentPkgAliases[pkgAddress.alias] !== true) {