Skip to content

Commit

Permalink
perf: reduce memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed May 15, 2024
1 parent 7113126 commit f5f9c05
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 9 deletions.
3 changes: 0 additions & 3 deletions pkg-manager/resolve-dependencies/src/resolveDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export interface ChildrenMap {
}

export type DependenciesTreeNode<T> = {
parentNodeId: string
children: (() => ChildrenMap) | ChildrenMap
installable: boolean
} & ({
Expand Down Expand Up @@ -752,7 +751,6 @@ async function resolveDependenciesOfDependency (
if (resolveDependencyResult == null) return { resolveDependencyResult: null }
if (resolveDependencyResult.isLinkedDependency) {
ctx.dependenciesTree.set(createNodeIdForLinkedLocalPkg(ctx.lockfileDir, resolveDependencyResult.resolution.directory), {
parentNodeId: options.parentPkg.nodeId,
children: {},
depth: -1,
installable: true,
Expand Down Expand Up @@ -901,7 +899,6 @@ async function resolveChildren (
depPath: child.depPath,
}))
ctx.dependenciesTree.set(parentPkg.nodeId, {
parentNodeId,
children: pkgAddresses.reduce((chn, child) => {
chn[child.alias] = (child as PkgAddress).nodeId ?? child.pkgId
return chn
Expand Down
2 changes: 0 additions & 2 deletions pkg-manager/resolve-dependencies/src/resolveDependencyTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export async function resolveDependencyTree<T> (

ctx.pendingNodes.forEach((pendingNode) => {
ctx.dependenciesTree.set(pendingNode.nodeId, {
parentNodeId: pendingNode.parentNodeId,
children: () => buildTree(ctx, pendingNode.nodeId, pendingNode.resolvedPackage.id,
pendingNode.parentDepPaths,
ctx.childrenByParentDepPath[pendingNode.resolvedPackage.depPath], pendingNode.depth + 1, pendingNode.installable),
Expand Down Expand Up @@ -290,7 +289,6 @@ function buildTree (
childrenNodeIds[child.alias] = childNodeId
installable = installable || !ctx.skipped.has(child.depPath)
ctx.dependenciesTree.set(childNodeId, {
parentNodeId,
children: () => buildTree(ctx,
childNodeId,
child.depPath,
Expand Down
6 changes: 2 additions & 4 deletions pkg-manager/resolve-dependencies/src/resolvePeers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,11 @@ function parentPkgsHaveSingleOccurrence (parentPkgs: Record<string, ParentPkgInf
// So we need to merge all the children of all the parent packages with same ID as the resolved package.
// This way we get all the children that were removed, when ending cycles.
function getPreviouslyResolvedChildren<T extends PartialResolvedPackage> (parentNodeIds: string[], parentDepPathsChain: string[], dependenciesTree: DependenciesTree<T>, ownDepPath: string): ChildrenMap {
const parentIds = [...parentNodeIds]
const parentDepPaths = [...parentDepPathsChain]
const allChildren: ChildrenMap = {}

if (!ownDepPath || !parentDepPaths.includes(ownDepPath)) return allChildren
if (!ownDepPath || !parentDepPathsChain.includes(ownDepPath)) return allChildren

for (const parentNodeId of parentIds.reverse()) {
for (const parentNodeId of [...parentNodeIds].reverse()) {
const parentNode = dependenciesTree.get(parentNodeId)!
if ((parentNode.resolvedPackage as T).depPath === ownDepPath) {
if (typeof parentNode.children === 'function') {
Expand Down

0 comments on commit f5f9c05

Please sign in to comment.