Repository navigation
fix(resolving-deps-resolver): stop re-walking a recorded subtree - #13575
Conversation
Winning the children-ownership claim is what licenses an occurrence to walk a package's manifest children. Concurrent occurrences of one package take turns winning it — each turn re-walked the whole subtree and left its occurrence nodes in the shared tree — so a chain of peer-carrying packages expanded exponentially with its depth. One project with one such dependency, over a graph of ~500 packages, could not finish inside 6 GB; at depth 22 it peaked at 4.1 GB. The TypeScript CLI resolves the same input in 1.06s and 263 MB. Winning the claim only means this occurrence outranks the one that recorded the children, not that the children differ. When the displaced owner resolved them under conditions this occurrence would reproduce — the same peer-shadowed set, the same update policy, the same prior-lockfile key — expand from the recorded children instead, exactly as a losing occurrence does. The three-part test is what keeps the reuse sound: an update-active occurrence re-resolves what a keep-all one reused, an occurrence pinned by a different snapshot key resolves different children, and a different shadow set drops different dependencies. Packages whose child specifiers pass through the importer's catalogs are excluded as well, being a property of the resolving importer rather than of the package id. Measured on the generated chain from #13574, one project, one dependency: | chain depth | before | after | |---|---|---| | 15 | 198,023 occurrence nodes, 278 MB, 1.00s | 3,211 nodes, 62 MB, 0.10s | | 20 | 4,463 MB, 17.5s | 71 MB, 0.17s | | 24 | did not finish in 180s under 6 GB | 78 MB, 0.20s | | 26 | did not finish | 78 MB, 0.19s | The emitted lockfile is byte-identical before and after, and byte-identical to the one the TypeScript CLI writes for the same input. Closes #13574.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe resolver records the context used to produce dependency children. Compatible recorded children are reused during ownership claims, while catalog-dependent workspace file resolutions continue with fresh subtree walks. A changeset documents bounded peer-chain resolution. ChangesPeer-chain subtree reuse
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant walk_node_children
participant WorkspaceTreeCtx
participant recorded_children
walk_node_children->>WorkspaceTreeCtx: build peer, lockfile, and update context
WorkspaceTreeCtx->>recorded_children: compare recorded child context
recorded_children-->>WorkspaceTreeCtx: return match status
WorkspaceTreeCtx-->>walk_node_children: reuse matching children lazily
walk_node_children->>WorkspaceTreeCtx: record children for the current owner
Assessment against linked issues
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoFix dependency tree resolver exponential growth by reusing recorded subtrees
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Confidence Score: 5/5The PR appears safe to merge because no eligible blocking failure or outstanding prior finding remains. No blocking failure remains. Reviews (5): Last reviewed commit: "test(resolving-deps-resolver): cover the..." | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs`:
- Around line 1145-1174: The children_context_unchanged calculation in the
workspace child-ownership flow must include the complete resolution context, not
only peer_shadowed. Require both peer_shadowed equality and
same_resolution_context to be true, preserving peer-shadowed,
owner.update_active, and prior_key semantics; add coverage for changed prior
keys and update policies.
- Around line 1177-1182: Bind each recorded children entry in workspace_ctx.rs
to the owning context or an ownership-generation token, and update
has_recorded_children to validate that identity rather than merely checking
presence. In walk.rs, create TreeChildren::Lazy only when the recorded entry
matches children_owner.owner; preserve lockfile compatibility and
prior-lockfile-key semantics, and add a deterministic test covering the
ownership handover interleaving. The workspace_ctx.rs anchor requires the
storage and validation change; the walk.rs sibling requires the matching-owner
check.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 10b532cc-9b66-4487-8979-a0ddbae62997
📒 Files selected for processing (5)
.changeset/bounded-peer-chain-resolution.mdpnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rspnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rspnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rspnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/tests.rs
Micro-Benchmark ResultsLinux |
Code Review by Qodo
1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main pnpm/pnpm#13575 +/- ##
=======================================
Coverage 87.98% 87.99%
=======================================
Files 563 563
Lines 97499 97561 +62
=======================================
+ Hits 85785 85846 +61
- Misses 11714 11715 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Integrated-Benchmark Report (Linux)Commit: Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm. Bencher consumes pacquet@HEAD and pnpr@HEAD. The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time). Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.62792154244,
"stddev": 0.182188828608349,
"median": 2.70492128444,
"user": 1.56150806,
"system": 1.3478228399999999,
"min": 2.34907930444,
"max": 2.84484821444,
"times": [
2.75148677744,
2.71874562344,
2.77834243444,
2.65046125244,
2.84484821444,
2.38019916044,
2.34907930444,
2.69153495844,
2.3962100884399997,
2.71830761044
]
},
{
"command": "pacquet@main",
"mean": 2.59268433574,
"stddev": 0.1597562853838713,
"median": 2.6567872584399996,
"user": 1.5082785599999997,
"system": 1.26090314,
"min": 2.3582185614399997,
"max": 2.79350401844,
"times": [
2.7468507884399997,
2.6555117394399996,
2.47780084444,
2.68962791644,
2.71425489844,
2.6580627774399996,
2.37807662244,
2.3582185614399997,
2.79350401844,
2.45493519044
]
},
{
"command": "pnpr@HEAD",
"mean": 1.4534537253400002,
"stddev": 0.09676473956057277,
"median": 1.44649679544,
"user": 1.02676626,
"system": 1.13457604,
"min": 1.35290109544,
"max": 1.6824360904400002,
"times": [
1.48847990144,
1.6824360904400002,
1.51445366244,
1.3820327304400002,
1.3974313224400001,
1.46063123644,
1.43550598044,
1.35290109544,
1.3631776234400002,
1.45748761044
]
},
{
"command": "pnpr@main",
"mean": 1.54119447414,
"stddev": 0.16770796720551967,
"median": 1.5157960299400002,
"user": 1.0367418599999998,
"system": 1.11068964,
"min": 1.3417709134400002,
"max": 1.7860142814400002,
"times": [
1.5225353974400002,
1.3724066844400002,
1.7464669454400001,
1.5090566624400001,
1.40412482844,
1.66740177244,
1.3417709134400002,
1.6835618754400001,
1.7860142814400002,
1.37860538044
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.26023065720000005,
"stddev": 0.008641614558327298,
"median": 0.25661757900000004,
"user": 0.19762948,
"system": 0.5464893,
"min": 0.252947323,
"max": 0.276367812,
"times": [
0.253592205,
0.25717898,
0.25403997700000003,
0.257142621,
0.255009521,
0.276367812,
0.252947323,
0.256092537,
0.266547827,
0.273387769
]
},
{
"command": "pacquet@main",
"mean": 0.2537394334,
"stddev": 0.01087580151666832,
"median": 0.25343586100000004,
"user": 0.21204128,
"system": 0.5197468999999999,
"min": 0.232633174,
"max": 0.266661029,
"times": [
0.232633174,
0.244357681,
0.255186503,
0.266661029,
0.264228717,
0.251685219,
0.24866501100000002,
0.262784261,
0.263760145,
0.247432594
]
},
{
"command": "pnpr@HEAD",
"mean": 0.2711662005,
"stddev": 0.010192232923943896,
"median": 0.2728555835,
"user": 0.20104608000000002,
"system": 0.5444799,
"min": 0.252981868,
"max": 0.284904364,
"times": [
0.261428631,
0.252981868,
0.26531015,
0.273835061,
0.264163764,
0.276606151,
0.28440783000000003,
0.27614808,
0.284904364,
0.271876106
]
},
{
"command": "pnpr@main",
"mean": 0.2677171587,
"stddev": 0.009912463930552584,
"median": 0.26844011,
"user": 0.21491477999999997,
"system": 0.530985,
"min": 0.25149936,
"max": 0.284225879,
"times": [
0.268149709,
0.276815203,
0.27260089,
0.25149936,
0.258991979,
0.273181201,
0.266842851,
0.256134004,
0.268730511,
0.284225879
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.5966354758000003,
"stddev": 0.020424482267653046,
"median": 2.5990642912,
"user": 1.49827524,
"system": 1.3139894,
"min": 2.5575800222,
"max": 2.6258072982,
"times": [
2.5575800222,
2.5761253842,
2.5832106672,
2.6000237112,
2.6039145382,
2.6094388362,
2.5925013262,
2.5981048712,
2.6196481032,
2.6258072982
]
},
{
"command": "pacquet@main",
"mean": 2.5965347268,
"stddev": 0.023085797154861972,
"median": 2.5880650877,
"user": 1.4589438399999999,
"system": 1.3126715,
"min": 2.5646550612,
"max": 2.6267565332,
"times": [
2.5792323272,
2.5840439892,
2.5897308182,
2.6267565332,
2.5863993572,
2.6263874992,
2.6215818472,
2.5646550612,
2.5742697712,
2.6122900642
]
},
{
"command": "pnpr@HEAD",
"mean": 1.4780956892,
"stddev": 0.05555497944143403,
"median": 1.4589969767,
"user": 1.01267554,
"system": 1.1225060999999998,
"min": 1.4206566962,
"max": 1.5740113262,
"times": [
1.4363706772,
1.4206566962,
1.5740113262,
1.4626822981999998,
1.5546735442,
1.5068382632,
1.4325262042,
1.4250906782,
1.4553116552,
1.5127955491999998
]
},
{
"command": "pnpr@main",
"mean": 1.6318071092,
"stddev": 0.16121720089415026,
"median": 1.5988876182,
"user": 0.9562164400000001,
"system": 1.2019829,
"min": 1.4339690852,
"max": 1.8435000451999999,
"times": [
1.4339690852,
1.6116566182,
1.4885336381999998,
1.7271969092,
1.8435000451999999,
1.5861186182,
1.5245293971999998,
1.8278971201999998,
1.8214872082,
1.4531824521999999
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.40054153826000005,
"stddev": 0.007383141353907032,
"median": 0.39825395016000004,
"user": 0.5005879999999999,
"system": 0.7190605399999999,
"min": 0.38945641116,
"max": 0.41041701216000004,
"times": [
0.39501841116,
0.39636028216,
0.40979042416000006,
0.41041701216000004,
0.40014761816000005,
0.40600585516000004,
0.40767064216000004,
0.38945641116,
0.39486332116000006,
0.39568540516000006
]
},
{
"command": "pacquet@main",
"mean": 0.39407488806,
"stddev": 0.005512723591966799,
"median": 0.39330476216,
"user": 0.528411,
"system": 0.6711917399999999,
"min": 0.38609453616000006,
"max": 0.40379353816,
"times": [
0.39362934216,
0.39708066516,
0.38609453616000006,
0.39084048216000006,
0.38992264816000005,
0.39620933916,
0.40103982516000003,
0.40379353816,
0.39298018216,
0.38915832216
]
},
{
"command": "pnpr@HEAD",
"mean": 0.30342168756000004,
"stddev": 0.008811496947007953,
"median": 0.30231046066,
"user": 0.204683,
"system": 0.52739344,
"min": 0.29211887816000004,
"max": 0.31980679716000004,
"times": [
0.29211887816000004,
0.30416771416000005,
0.29532405116000005,
0.30045320716,
0.29686652816000003,
0.31113385316000003,
0.30698364516000004,
0.31980679716000004,
0.31117600216,
0.29618619916000005
]
},
{
"command": "pnpr@main",
"mean": 0.30176247816,
"stddev": 0.005975792955578064,
"median": 0.30037559616000004,
"user": 0.19418019999999997,
"system": 0.54276444,
"min": 0.29450701416,
"max": 0.31379800916,
"times": [
0.29835496416,
0.31379800916,
0.30365433116,
0.29450701416,
0.30057323216000004,
0.29464852116,
0.29886479216,
0.30604853816000005,
0.30017796016000003,
0.30699741916
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.7326179263600001,
"stddev": 0.011464616384360264,
"median": 1.73493621076,
"user": 0.70994916,
"system": 0.7560375799999999,
"min": 1.71779633526,
"max": 1.7516898602600002,
"times": [
1.73712607426,
1.73521890226,
1.71779633526,
1.7193142862600002,
1.7516898602600002,
1.7473989812600002,
1.7231912202600002,
1.7240158792600002,
1.73465351926,
1.73577420526
]
},
{
"command": "pacquet@main",
"mean": 1.7402216638599999,
"stddev": 0.006184041045804154,
"median": 1.73929537926,
"user": 0.7132006599999998,
"system": 0.7722449799999999,
"min": 1.72733440126,
"max": 1.7486205052600001,
"times": [
1.73816481526,
1.74684871626,
1.73544415426,
1.74476756726,
1.7387869742600002,
1.7436587462600002,
1.73888731226,
1.73970344626,
1.72733440126,
1.7486205052600001
]
},
{
"command": "pnpr@HEAD",
"mean": 0.3016626480599999,
"stddev": 0.004713921522598705,
"median": 0.30180563876,
"user": 0.20259136,
"system": 0.5193799799999999,
"min": 0.29425772026,
"max": 0.30937931526,
"times": [
0.29949063026,
0.30293998926,
0.30594649726,
0.30067128826,
0.29692538226,
0.30937931526,
0.29425772026,
0.29747498326,
0.30420798126,
0.30533269326
]
},
{
"command": "pnpr@main",
"mean": 0.30039267466,
"stddev": 0.006948729596721635,
"median": 0.30127339276,
"user": 0.19952266000000002,
"system": 0.53194008,
"min": 0.28585990526,
"max": 0.30871010426,
"times": [
0.28585990526,
0.29407044826,
0.30035685726,
0.30871010426,
0.30499944526,
0.29707195526,
0.29843610726,
0.30218992826,
0.30828280326,
0.30394919226
]
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.18119906164769234,
"stddev": 0.012574168092208661,
"median": 0.17801402634000002,
"user": 0.16740137076923073,
"system": 0.06727931076923077,
"min": 0.17296189734000003,
"max": 0.22244982134000002,
"times": [
0.22244982134000002,
0.18134496334000003,
0.17296189734000003,
0.17812113734,
0.18080582134,
0.17801402634000002,
0.17694267434000002,
0.17664805134000003,
0.17635630234000002,
0.17800544134000001,
0.17913045434000002,
0.17851631034,
0.17629090034000003
]
},
{
"command": "pacquet@main",
"mean": 0.1796467924025,
"stddev": 0.004328859924244665,
"median": 0.17952951834000003,
"user": 0.16746488999999995,
"system": 0.06791339249999997,
"min": 0.17203659934,
"max": 0.18849703734,
"times": [
0.17622860334,
0.18267859834000003,
0.17642740734,
0.17992916334000003,
0.18849703734,
0.18135379034000002,
0.18422802934000002,
0.17688641834000002,
0.18384582034000002,
0.17849863734000002,
0.17912987334000002,
0.17287880034000003,
0.18215138834000003,
0.17203659934,
0.18209854834000003,
0.17747996334000002
]
},
{
"command": "pnpr@HEAD",
"mean": 0.08701837021878789,
"stddev": 0.001612788427583996,
"median": 0.08728331634,
"user": 0.02266132181818182,
"system": 0.007140830303030303,
"min": 0.08251706334,
"max": 0.09070977134,
"times": [
0.08609146734,
0.08706636733999999,
0.08743647434,
0.08744945734,
0.08724737834,
0.08801578034,
0.08596326734,
0.08335506734,
0.08667810934,
0.08817950934,
0.08652920934,
0.08251706334,
0.08744283434,
0.08702764534,
0.08802022034,
0.08719710334,
0.08728331634,
0.09070977134,
0.08619569234,
0.08523506834,
0.08944201134,
0.08567090734,
0.08679666134,
0.08893647034,
0.08448462933999999,
0.08846598834,
0.08761150234,
0.08824440034,
0.08764490534,
0.08563488034,
0.08735897734,
0.08810759334,
0.08756648734
]
},
{
"command": "pnpr@main",
"mean": 0.0870019400275,
"stddev": 0.0014418201500872349,
"median": 0.08687255984,
"user": 0.019698796249999997,
"system": 0.009457199999999999,
"min": 0.08441346534,
"max": 0.09005937934,
"times": [
0.08825695534,
0.08441346534,
0.08517333234,
0.08766361934,
0.08529633334,
0.08828567833999999,
0.08639967634,
0.08675198734,
0.08751829634,
0.08789077734,
0.08952714034,
0.08621695334,
0.08626561334,
0.08927529634,
0.08621714334,
0.08583912234,
0.08486322034,
0.08622574934,
0.08737952634,
0.08650076634,
0.08726381933999999,
0.08774045434,
0.08676173633999999,
0.08769473834,
0.08780256134,
0.08698338334,
0.09005937934,
0.08496229634,
0.08914918034,
0.08840802834,
0.08513944933999999,
0.08613640134
]
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.7675145068511111,
"stddev": 0.14650661993776826,
"median": 0.72674816574,
"user": 0.7138951444444444,
"system": 0.15765670666666665,
"min": 0.5492819277400001,
"max": 0.9782404787400001,
"times": [
0.5492819277400001,
0.66234608874,
0.9782404787400001,
0.6714153927400001,
0.86317374674,
0.96633207074,
0.80843618174,
0.6816565087400001,
0.72674816574
]
},
{
"command": "pacquet@main",
"mean": 1.2520534924066669,
"stddev": 0.24785392845040108,
"median": 1.16017486774,
"user": 1.1747108111111109,
"system": 0.15684326222222222,
"min": 0.84651737374,
"max": 1.58815895474,
"times": [
1.1183598587399999,
1.58815895474,
1.05384322174,
1.16017486774,
1.4552035327400001,
1.49349726774,
1.43075908974,
0.84651737374,
1.12196726474
]
},
{
"command": "pnpm@HEAD",
"mean": 2.930953863517778,
"stddev": 0.04574770001016976,
"median": 2.95639787574,
"user": 4.459335366666667,
"system": 0.26324548444444446,
"min": 2.83836864874,
"max": 2.97401580674,
"times": [
2.96225025674,
2.97401580674,
2.95639787574,
2.91713545174,
2.83836864874,
2.96306283374,
2.96138775874,
2.92508187574,
2.88088426374
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.56101262992,
"stddev": 0.16103246137920188,
"median": 4.46865195062,
"user": 1.6933780999999999,
"system": 1.3153194999999998,
"min": 4.40300869712,
"max": 4.86620979012,
"times": [
4.43712287412,
4.49028678912,
4.44701711212,
4.44333550312,
4.67050748612,
4.86620979012,
4.40300869712,
4.73875004412,
4.66754692512,
4.44634107812
]
},
{
"command": "pacquet@main",
"mean": 4.49571605312,
"stddev": 0.08556690343576721,
"median": 4.44986980212,
"user": 1.6496336000000003,
"system": 1.4144425999999999,
"min": 4.42173672612,
"max": 4.64567267012,
"times": [
4.58685155712,
4.42802569812,
4.42248833512,
4.64567267012,
4.42173672612,
4.44200453812,
4.45773506612,
4.42913450212,
4.52857211012,
4.594939328120001
]
},
{
"command": "pnpr@HEAD",
"mean": 3.51912849992,
"stddev": 0.11642562273054438,
"median": 3.47822171512,
"user": 1.1807892,
"system": 1.1916442,
"min": 3.43876891812,
"max": 3.82239465912,
"times": [
3.52174468412,
3.5025562591200003,
3.43876891812,
3.45614982712,
3.59572221612,
3.4768207861200002,
3.43886075112,
3.82239465912,
3.47962264412,
3.45864425412
]
},
{
"command": "pnpr@main",
"mean": 3.6057909414199996,
"stddev": 0.11577727385034509,
"median": 3.6299241166200003,
"user": 1.1493555,
"system": 1.2207386,
"min": 3.44896978012,
"max": 3.76033076712,
"times": [
3.6632453601200003,
3.4550448081200003,
3.68587585512,
3.76033076712,
3.59660287312,
3.72176734612,
3.5036846291200003,
3.44896978012,
3.69981094712,
3.52257704812
]
}
]
} |
|
| Project | pnpm's project |
| Branch | pr/13575 |
| Testbed | pnpr |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 1,420.66 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 294.26 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 292.12 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 82.52 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,352.90 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,438.77 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 252.98 ms |
Review of the first version found the reuse test asking the wrong object. It compared this occurrence against the owner standing at claim time, but `children_by_id` is written by whichever walk completed, and that walk need not be the standing owner's: an occurrence could inherit children recorded under a context nobody had checked it against. Record the context each `children_by_id` entry was produced under — shadowed set, prior-lockfile key, update policy — and compare against that instead of against the claim. The claim goes back to reporting only what it can know, and `children_context_unchanged` returns to its own job of keeping a reused subtree alive across a handover; tightening that flag instead breaks `unchanged_shadow_ownership_handover_keeps_reused_subtree`, which is the behaviour it exists to pin. The preferred-versions overlay is deliberately not part of the test, and that is a judgement rather than an oversight: `children_by_id` holds one child list per package id, every non-owner occurrence already expands from it whatever its own overlay says, and requiring identical overlays means requiring identical parents — which never holds for the occurrences that race. Measured, that requirement reinstates the expansion in full: depth 15 goes back to 299 MB and depth 26 stops finishing. Related to #13574.
The reuse decision moved to the recorded-children context, so the ownership entry no longer needs to carry it. Related to #13574.
|
All three findings were right, and two of them changed the design. Pushed as 8d46c1c. "Bind recorded children to the ownership generation" (CodeRabbit) — taken. This was the real defect: my test compared this occurrence against the owner standing at claim time, but "Include the full resolution context in "Overlay omitted from reuse" (Qodo) — real, and deliberately not fixed by requiring overlay equality. I implemented it to find out what it costs: with overlay identity in the test, depth 15 goes from 62 MB / 0.10s back to 299 MB / 1.03s, depth 20 to 3.7 GB / 12.1s, and depth 26 stops finishing. The reason is structural — occurrences that race for a claim are reached from different parents, so they never share an overlay layer, and requiring identical overlays means requiring identical parents. The judgement I made instead, now written into the code: If that trade is not acceptable, the fix that removes the race outright is to settle ownership before descending (process claims in rank order, so the first claim is the final one) rather than cleaning up after it. That is a restructuring of the concurrent walk rather than a guard, so I would want it as its own change. Verification after the rework: 7,555 tests pass, depths 15/20/26 resolve in 62/62/83 MB and 0.10/0.12/0.20s, and the emitted lockfile is still byte-identical to the TypeScript CLI's for the same input. Written by an agent (Claude Code, claude-opus-5). |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs`:
- Around line 1195-1212: Consolidate each package’s recorded child edges and
RecordedChildrenContext into a single mutex-protected entry, replacing the
separate children_by_id and children_context_by_id coordination. Update
recorded_children_match and record_children_context to use this atomic entry,
and provide one accessor that returns the matching child-edge snapshot with its
context validation. Ensure subtree reuse only uses edges matched to the same
prior_key and update_active values, preserving resolution decisions and lockfile
output under concurrent walks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: e19227d8-5d49-482f-a6fe-9486e954b86a
📒 Files selected for processing (2)
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rspnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs
|
Code review by qodo was updated up to the latest commit 8d46c1c |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
…t together Review found the reuse test reading the context from one mutex and the edges it describes from another, so a reader could accept a context one walk recorded and then expand the edges a different walk wrote. Hold both halves in one `children_by_id` entry and record them together, so a matched context always describes the edges that come with it. Also repairs the intra-doc link left behind when the reuse flag moved off the ownership claim, which `cargo doc --document-private-items` rejects. Related to #13574.
… the test module The dylint rule the pre-push hook runs rejects inline test code in a production file. Related to #13574.
|
Pushed 2a14486, which covers both of the new findings and the two red checks. "Store recorded child edges and their context atomically" (CodeRabbit) — taken. The two maps were written and read under separate mutexes, so a reader could accept a context one walk recorded and then expand the edges another walk wrote. "Missing reuse context record" (Qodo) — real on 8d46c1c, and fixed by the same rework. The lockfile-reuse path wrote
On comment conventions, one of mine broke them: the note at the reuse site narrated what the walk used to do, which belongs in the commit message. It now states the standing contract and the reason, and the overlay rationale is a statement of the invariant rather than a retelling of the experiment that produced it. Verification after the rework: 7,555 tests pass, dylint and the private-items doc build are clean, depths 15/26 of the issue's fixture resolve in 61 MB / 0.10s and 78 MB / 0.17s, and the emitted lockfile is still byte-identical to the TypeScript CLI's. Written by an agent (Claude Code, claude-opus-5). |
|
Code review by qodo was updated up to the latest commit 0fd2424 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
"Orphaned walked subtrees" (Qodo) — real, pre-existing, and bounded; not changing it here. The observation is correct: an occurrence that starts walking as owner and loses the claim before publishing leaves its descendant occurrence nodes in the shared tree, unreachable from a parent that ends up lazy. Two things frame it:
Reclaiming them properly means tracking every node a walk materialised so a losing walk can retract its subtree — which is bookkeeping in the hot path to undo work that should not have happened. The change that removes the cause instead is settling ownership before descending, so only the eventual owner walks: it also answers the overlay question, since a single deterministic walker makes "which occurrence's versions get recorded" a settled question rather than a race. That is a restructuring of the concurrent walk and belongs in its own PR, which I would rather size against the real workspaces than bolt onto this fix.
Written by an agent (Claude Code, claude-opus-5). |
…ates Codecov flagged the new gates as uncovered. Both are testable without the ownership race that the reuse itself needs: one pins that each field of the recorded context can withhold reuse, the other that a walk which lost the claim while it ran cannot overwrite the standing owner's children. Both were checked against implementations with those conditions removed. Related to #13574.
|
Codecov flagged the new gates as uncovered, and unlike the race itself those are testable directly — pushed 4caad19 with two unit tests:
Both were verified against implementations with those conditions removed — dropping the ownership check in That leaves the reuse path itself uncovered, for the reason given earlier in the PR: it needs occurrences of one package to race for the claim, which an in-process 7,557 tests pass. Written by an agent (Claude Code, claude-opus-5). |
|
Code review by qodo was updated up to the latest commit 4caad19 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Summary
Fixes #13574: a dependency chain whose packages carry peer dependencies
made resolution cost grow exponentially with the depth of the chain. One project
with one dependency, over a graph of ~500 packages, could not finish inside
6 GB. The TypeScript CLI resolves the same input in 1.06s / 263 MB.
The mechanism
Winning the children-ownership claim is what licenses an occurrence to walk a
package's manifest children — a loser stays lazy and expands from the recorded
children_by_id. Concurrent occurrences of the same package take turns winningthat claim, and each turn re-walked the entire subtree, leaving its
occurrence nodes in the shared tree forever. Those nodes then issue claims of
their own, which is the multiplication.
Counters on the fixture, single importer, single dependency — note that the
number of claims won dwarfs the package count, while at most one occurrence
per package can be the final owner:
Every winning claim beyond the package count re-walked a subtree that resolves
identically. The memory is all in
dependencies_tree: every peer-walkerstructure stays under 1,000 entries, and the tree is fully populated before
the peer pass starts.
The change
Winning the claim only means this occurrence outranks the one that recorded the
children, not that the children differ. When the displaced owner resolved them
under conditions this occurrence would reproduce, expand from the recorded
children instead — exactly what a losing occurrence does.
"Conditions this occurrence would reproduce" is a three-part test, and each part
is load-bearing:
dependencies (this part already existed as
children_context_unchanged);keep-all one reused, so inheriting a keep-all walk's children would silently
defeat
pacquet update;key resolves different children. This is the part the adversarial-interleaving
tests from fix(resolving-deps-resolver): derive peer-hoist version candidates from the settled tree #13570 and test(resolving-deps-resolver): cover the required-peer picker under the adversarial interleaving #13572 caught when I first wrote the
guard without it; they fail without this term and pass with it.
Packages whose child specifiers pass through the importer's catalogs are
excluded too, being a property of the resolving importer rather than of the
package id.
Result
Output is unchanged: the emitted lockfile is byte-identical before and after,
and byte-identical to the one the TypeScript CLI writes for the same input.
On the 114-project Bit workspace from pnpm/tasks#16 the change is neutral
(12.30–13.03s / 7.5–7.9 GB on main; 11.97–13.18s / 7.5–8.0 GB here) — that
workspace is wide rather than deep, so it barely takes the re-walk path. Its
~7.5 GB peak is a separate problem, and its run-to-run lockfile instability is
too: two consecutive runs of main on it still differ by 9,194 lines, so
#13567 is not fully closed. I will report that separately.
On the missing regression test
I could not build one that fails without this fix, and I would rather say so
than add a test that passes either way. The blowup needs occurrences of one
package to race for the claim; an in-process
resolve_workspacetest does notproduce that, at any shape I tried — a yielding resolver, a multi-threaded
runtime, and the CLI fixture's exact dimensions (12 layers x 20 packages, 4
children, 30 providers, 8 peers each) all give the same 631 occurrence nodes
with and without the fix, while the CLI on that same shape gives 23,479 without
and ~2,600 with.
The guard that would work drives the real CLI: the multi-importer hoist-heavy
scenario I have prototyped for the integrated benchmark, sized below this
blowup. I will propose it separately, with the A/B that shows it discriminates.
Squash Commit Body
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Performance Improvements
Reliability Improvements