Commit a1c0656
authored
perf: Replace O(N) workspace path lookup with HashMap index in DependencySplitter (#11922)
## Summary
`DependencySplitter::workspace()` did a linear scan over all workspaces
to find a package by its directory path. This is called for every
`workspace:` path-based dependency during
`connect_internal_dependencies` — O(N) per lookup, O(N²) total for repos
using path-based workspace protocol references (e.g.
`workspace:../sibling-pkg`).
Adds `WorkspacePathIndex` — a `HashMap<&AnchoredSystemPath,
&PackageName>` built once before the dependency resolution loop and
shared across all `DependencySplitter` instances. Lookups go from O(N)
linear scan to O(1).
### Changes
**`dep_splitter.rs`**: New `WorkspacePathIndex` struct built from the
workspaces HashMap. `DependencySplitter::new` takes a shared
`&WorkspacePathIndex` reference. `workspace()` uses an O(1) HashMap
lookup instead of `iter().find()`.
**`builder.rs`**: `connect_internal_dependencies` builds the
`WorkspacePathIndex` once before the loop. `Dependencies::new` passes it
through to the splitter.1 parent f8717d4 commit a1c0656
File tree
2 files changed
+35
-6
lines changed- crates/turborepo-repository/src/package_graph
2 files changed
+35
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
392 | 393 | | |
393 | 394 | | |
394 | 395 | | |
| 396 | + | |
395 | 397 | | |
396 | 398 | | |
397 | 399 | | |
| |||
405 | 407 | | |
406 | 408 | | |
407 | 409 | | |
| 410 | + | |
408 | 411 | | |
409 | 412 | | |
410 | 413 | | |
| |||
601 | 604 | | |
602 | 605 | | |
603 | 606 | | |
| 607 | + | |
604 | 608 | | |
605 | 609 | | |
606 | 610 | | |
607 | 611 | | |
608 | 612 | | |
609 | 613 | | |
610 | 614 | | |
611 | | - | |
612 | | - | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
613 | 622 | | |
614 | 623 | | |
615 | 624 | | |
| |||
Lines changed: 23 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
11 | 26 | | |
12 | 27 | | |
13 | 28 | | |
14 | 29 | | |
| 30 | + | |
15 | 31 | | |
16 | 32 | | |
17 | 33 | | |
| |||
21 | 37 | | |
22 | 38 | | |
23 | 39 | | |
| 40 | + | |
24 | 41 | | |
25 | 42 | | |
26 | 43 | | |
27 | 44 | | |
28 | 45 | | |
29 | 46 | | |
| 47 | + | |
30 | 48 | | |
31 | 49 | | |
32 | 50 | | |
| |||
86 | 104 | | |
87 | 105 | | |
88 | 106 | | |
89 | | - | |
90 | | - | |
91 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
92 | 110 | | |
93 | 111 | | |
94 | 112 | | |
| |||
305 | 323 | | |
306 | 324 | | |
307 | 325 | | |
| 326 | + | |
308 | 327 | | |
309 | 328 | | |
310 | 329 | | |
311 | 330 | | |
| 331 | + | |
312 | 332 | | |
313 | 333 | | |
314 | 334 | | |
| |||
0 commit comments