Commit fc19b66
authored
perf: Reduce per-package hashing overhead and eliminate SCM subprocesses (#11942)
## Summary
Follow-up to #11938. Targets the per-package hashing hot path that
dominates at scale, plus eliminates the last two git subprocesses from
`--dry` runs.
### Small repo (~6 packages)
| | Mean | Range |
|---|---|---|
| **This PR** | 571.2ms ± 46.7ms | 515.6ms - 651.7ms |
| **main** | 587.4ms ± 45.1ms | 524.9ms - 676.3ms |
| | **1.03 ± 0.12x faster** | |
### Medium repo (~120 packages)
| | Mean | Range |
|---|---|---|
| **This PR** | 1.096s ± 0.095s | 1.015s - 1.280s |
| **main** | 1.119s ± 0.072s | 1.042s - 1.259s |
| | **1.02 ± 0.11x faster** | |
### Large repo (~1000 packages)
| | Mean | Range |
|---|---|---|
| **This PR** | 1.729s ± 0.151s | 1.548s - 1.969s |
| **main** | 1.833s ± 0.181s | 1.583s - 2.099s |
| | **1.06 ± 0.14x faster** | |
The small repo results best isolate the fixed-cost improvements (git2
for branch/SHA, reduced allocation overhead) since per-package work is
minimal. At larger scales, the improvements are present but within noise
because wall-clock time is already well-parallelized across rayon
threads.
## Benchmarks
All benchmarks: `turbo run <task> --skip-infer --dry`, 5 warmup + 10
measured runs, release build.
## Changes
- **FileHashes: HashMap to sorted Vec** — `FileHashes` inner type
changed from `HashMap` to pre-sorted `Vec`. Eliminates HashMap
construction (hashing, bucket allocation, rehashing) in the per-package
hashing pipeline and removes redundant re-sorting in Cap'n Proto
serialization. The sort happens once at the construction boundary;
downstream consumers (`expanded_inputs`, `.hash()`) get pre-sorted data
for free.
- **Status entry binary search** — `get_package_hashes` now uses
`partition_point` on pre-sorted status entries instead of a linear scan.
Reduces per-package status lookup from O(dirty_files) to
O(log(dirty_files) + matched). Also adds `with_capacity` to the
per-package HashMap to avoid rehashing.
- **git2 for branch/SHA** — `get_current_branch` and `get_current_sha`
(called by `SCMState::get` in `to_summary`) now use `git2::Repository`
instead of forking `git branch --show-current` and `git rev-parse HEAD`.
Gated behind `#[cfg(feature = "git2")]` with subprocess fallback.1 parent ef6dfd2 commit fc19b66
File tree
7 files changed
+431
-91
lines changed- crates
- turborepo-hash/src
- turborepo-run-cache/src
- turborepo-run-summary/src
- turborepo-scm/src
- turborepo-task-hash/src
- turborepo-types/src
7 files changed
+431
-91
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
228 | 233 | | |
229 | 234 | | |
230 | 235 | | |
| |||
236 | 241 | | |
237 | 242 | | |
238 | 243 | | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
| 244 | + | |
246 | 245 | | |
247 | 246 | | |
248 | 247 | | |
| |||
268 | 267 | | |
269 | 268 | | |
270 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
271 | 275 | | |
272 | 276 | | |
273 | 277 | | |
| |||
279 | 283 | | |
280 | 284 | | |
281 | 285 | | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
| 286 | + | |
286 | 287 | | |
287 | 288 | | |
288 | 289 | | |
| |||
590 | 591 | | |
591 | 592 | | |
592 | 593 | | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
593 | 603 | | |
594 | 604 | | |
595 | 605 | | |
| |||
600 | 610 | | |
601 | 611 | | |
602 | 612 | | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
| 613 | + | |
610 | 614 | | |
611 | 615 | | |
612 | 616 | | |
613 | 617 | | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
624 | 622 | | |
625 | 623 | | |
626 | 624 | | |
| |||
630 | 628 | | |
631 | 629 | | |
632 | 630 | | |
633 | | - | |
| 631 | + | |
| 632 | + | |
634 | 633 | | |
635 | 634 | | |
636 | 635 | | |
637 | 636 | | |
638 | | - | |
| 637 | + | |
| 638 | + | |
639 | 639 | | |
640 | 640 | | |
641 | 641 | | |
| |||
683 | 683 | | |
684 | 684 | | |
685 | 685 | | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
686 | 743 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
485 | 485 | | |
486 | 486 | | |
487 | 487 | | |
488 | | - | |
489 | | - | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
490 | 491 | | |
491 | 492 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
130 | 132 | | |
131 | 133 | | |
132 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
175 | 191 | | |
176 | 192 | | |
177 | 193 | | |
178 | 194 | | |
179 | 195 | | |
180 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
181 | 211 | | |
182 | 212 | | |
183 | 213 | | |
| |||
1422 | 1452 | | |
1423 | 1453 | | |
1424 | 1454 | | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
1425 | 1554 | | |
0 commit comments