Commit fd1b6e8
authored
perf: Improve transitive dependency resolution cache sharing across workspaces (#11903)
## Summary
The `ResolveCache` used during pnpm lockfile transitive closure
computation keyed entries by `(workspace_path, package_name,
specifier)`. This meant two workspaces resolving the same transitive
sub-dependency (e.g. `lodash@4.17.21`) would each miss the cache and
resolve independently — the workspace path made the keys differ. For a
monorepo with N workspaces sharing a common dependency tree, this caused
O(N*D) resolution work instead of O(N+D).
The fix splits cache key strategy by resolution phase:
- **Direct workspace deps** (root level): include `workspace_path` in
the key, since `resolve_specifier` needs the workspace's importer entry.
- **Transitive sub-deps** (recursive): omit `workspace_path`, since
`resolve_package` resolves these by direct lockfile key lookup,
independent of which workspace started the traversal.
Also removes `#[tracing::instrument]` from `resolve_package` (~332k
calls) and `all_dependencies` (~329k calls). At this call volume, span
creation/entry/exit overhead is significant — `all_dependencies` is a
single HashMap lookup where the tracing cost exceeded the function body.
## Benchmarks
All benchmarks are `turbo run <task> --skip-infer --no-daemon --dry`
with `--warmup 5`.
**Repo A — ~1000 packages (pnpm)**
| | Before | After | Speedup |
|---|---|---|---|
| Wall clock | 4.210s ± 0.087s | 2.165s ± 0.034s | **1.94x** |
| User time | 29.624s | 3.705s | **8.0x** (CPU work) |
**Repo B — ~100 packages (pnpm)**
| | Before | After | Speedup |
|---|---|---|---|
| Wall clock | 1.376s ± 0.116s | 1.323s ± 0.092s | 1.04x |
| User time | 3.522s | 0.801s | **4.4x** (CPU work) |
**Repo C — ~6 packages (pnpm)**
| | Before | After | Speedup |
|---|---|---|---|
| Wall clock | 694.6ms ± 85.4ms | 669.5ms ± 37.0ms | ~1.0x (within
noise) |
The improvement scales with the number of workspaces sharing transitive
dependencies, which is why the 1000-package repo sees the largest gain.
Repo B shows a dramatic CPU reduction (4.4x) that translates to a modest
wall-clock improvement because the old code hid redundant work behind
rayon parallelism, and other costs (globwalk, git operations) now
dominate.1 parent 57cf69c commit fd1b6e8
2 files changed
+90
-81
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
176 | | - | |
177 | | - | |
| 175 | + | |
178 | 176 | | |
179 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
180 | 183 | | |
181 | 184 | | |
182 | 185 | | |
183 | | - | |
184 | | - | |
| 186 | + | |
185 | 187 | | |
186 | | - | |
187 | 188 | | |
188 | 189 | | |
189 | 190 | | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
198 | 196 | | |
199 | 197 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
209 | 213 | | |
210 | | - | |
211 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
212 | 221 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
228 | 230 | | |
229 | | - | |
230 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
231 | 255 | | |
| 256 | + | |
| 257 | + | |
232 | 258 | | |
233 | 259 | | |
234 | | - | |
235 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
236 | 272 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
254 | 277 | | |
255 | | - | |
256 | | - | |
257 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
258 | 283 | | |
259 | 284 | | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
| 285 | + | |
273 | 286 | | |
274 | | - | |
275 | | - | |
276 | 287 | | |
277 | 288 | | |
278 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
468 | 468 | | |
469 | 469 | | |
470 | 470 | | |
471 | | - | |
472 | 471 | | |
473 | 472 | | |
474 | 473 | | |
| |||
520 | 519 | | |
521 | 520 | | |
522 | 521 | | |
523 | | - | |
524 | 522 | | |
525 | 523 | | |
526 | 524 | | |
| |||
0 commit comments