turbo
c0a8996f - perf: Index Bun nested lockfile entries by name for fallback resolution (#13633)

Commit
86 days ago
perf: Index Bun nested lockfile entries by name for fallback resolution (#13633) BunLockfile::find_matching_version falls back to scanning every entry in the packages section whenever the workspace-scoped and hoisted lookups don't satisfy a dependency's version spec — a common case for any nested or conflicting-version dependency. Each scanned entry paid a PackageIdent::parse (two heap allocations) just to compare names, and the scan re-ran per unresolved edge per workspace, making resolution effectively O(edges × workspaces × packages) on large Bun monorepos. Add a nested_by_name map to PackageIndex, built during the existing single pass over the packages section: entries whose key contains '/' (nested or scoped top-level), excluding bundled deps and workspace mappings, grouped by their ident's package name. Buckets preserve the BTreeMap's sorted key order, so lookups return the same entry the full scan previously found first. find_matching_version now visits only entries actually named for the dependency instead of every package. On a synthetic bun.lock with 4,000 packages and 50 workspaces where every edge requires the fallback, all_transitive_closures drops from 2.37s to 0.15s (16x); the gap grows with lockfile size since the old scan was linear in total packages per edge. Co-authored-by: Claude <noreply@anthropic.com>
Author
Parents
Loading