{{ message }}
Repository navigation
fix(arborist): use a set for bundled-dependency traversal - #10127
Open
jeffwidman wants to merge 1 commit into
Open
jeffwidman wants to merge 1 commit into
jeffwidman wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
jeffwidman
marked this pull request as ready for review
October 15, 2026 03:48
This was referenced Oct 15, 2026
martinrrm
approved these changes
Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Use a traversal-local
Setto track visited nodes in Arborist’sgetBundler(), while retaining the existing behavior for explicitly supplied arrays.Why this should reduce work
The existing
patharray is a visited collection, not a stack: nodes are appended and never popped. Eachincludes()searches the growing collection again. A dependency shared by many packages can therefore require substantial repeated scanning even though the traversal already avoids revisiting nodes.A set expresses the same visited-node membership test without those linear searches. This does not change traversal order, bundle selection, or the dependency graph, and does not introduce a persistent cache or invalidation rules.
Compatibility
The optional traversal argument is exposed as an array in the public TypeScript declarations. Explicit arrays therefore continue through the original array operations, including mutation order, existing duplicates, and already-visited behavior. Only normal calls that omit the argument start with a set.
The added regression test covers those array behaviors and verifies that separate default calls have independent traversal state.
Local measurements
I applied this same method change directly to an isolated npm 11.17.0 installation, using Node 24.22.0. These final measurements do not use a preload hook or a CPU profiler.
For a large workspace snapshot with 5,405 original lockfile entries, I updated
prettierto 3.9.10 with:Each sample started from the same manifests and lockfile, in a fresh directory, with a warmed metadata cache. After one warmup per variant, three measured pairs alternated execution order.
Every resulting lockfile was byte-identical across variants.
A tiny-project control with one local dependency used seven measured alternating pairs, excluding warmups:
Those control differences are effectively noise. These are local native-command measurements, not a claim about every project or complete dependency-update jobs. The large workspace fixture is not included; the public synthetic example below reproduces the eliminated membership-search work without relying on that fixture.
Validation
On this PR’s upstream checkout, using Node 24.22.0:
node bin/npm-cli.js test --workspace=@npmcli/arborist --ignore-scripts -- --jobs=4— passed: 59 test files; 100% statements, branches, functions, and lines.node node_modules/eslint/bin/eslint.js workspaces/arborist/lib/node.js workspaces/arborist/test/node.js— passed.Public synthetic reproduction of the avoided work
Run this from the patched repository root after installing its development dependencies. It constructs 512 packages sharing one dependency and compares the retained array path with the set path.
The counts are logical membership-search work, not a timing benchmark or an estimate of overall speedup.
The same 1,538 membership checks search 133,889 array entries in total; the set performs 1,538 membership lookups. Both return the same result.
Prepared with assistance from GitHub Copilot. The validation results above were obtained locally.
References
getBundler(path?: Node[]).