Commit b8fba56
perf(repartition): drop redundant reservation Mutex and halve per-batch Instant::now() calls
`SharedMemoryReservation` wraps `MemoryReservation` in an `Arc<Mutex<_>>`,
but every method on `MemoryReservation` (`try_grow`, `shrink`, `try_resize`,
...) already takes `&self` and mutates an `AtomicUsize` internally. The
extra `Mutex` is dead weight on the hot path: both the producer (`try_grow`
in `pull_from_input`) and the consumer (`shrink` in `PerPartitionStream`)
paid a lock acquire per batch for no correctness benefit.
Type the three fields in `repartition/mod.rs` as `Arc<MemoryReservation>`
and drop the three `.lock()` callsites. The shared-channel alias
`SharedMemoryReservation` in `common.rs` stays as-is for now — it is still
used by `symmetric_hash_join`.
Independently, the per-sub-batch `send_time[partition].timer()` idiom
calls `Instant::now()` twice per sub-batch (once at `timer()`, once at
`done()`/drop). Replace with a single advancing `Instant` that tracks
elapsed-since-last-partition, giving one `Instant::now()` per sub-batch
while preserving the per-partition `send_time` metric.
Also add a criterion microbench (`benches/repartition.rs`) that drives a
1M-row, 16-input / 16-output hash repartition, a round-robin variant, and
a 16→1 coalesce.
Before / after on the new bench (macOS ARM):
hash_16_to_16 1.62 ms -> 1.55 ms (~ -2.5%)
round_robin_16_to_16 303 us -> 268 us (~ -10%)
hash_16_to_1_coalesce 932 us -> 917 us (~ -5%)
The hash case is dominated by `BatchPartitioner` hashing itself, so the
plumbing wins show up most clearly on the round-robin variant.
All 41 existing `repartition` unit tests pass, including spill and
memory-pool paths.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 43d32a8 commit b8fba56
3 files changed
Lines changed: 192 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| |||
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
61 | | - | |
| 60 | + | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
| |||
143 | 142 | | |
144 | 143 | | |
145 | 144 | | |
146 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
147 | 151 | | |
148 | 152 | | |
149 | | - | |
| 153 | + | |
150 | 154 | | |
151 | 155 | | |
152 | 156 | | |
| |||
177 | 181 | | |
178 | 182 | | |
179 | 183 | | |
180 | | - | |
| 184 | + | |
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
| |||
322 | 326 | | |
323 | 327 | | |
324 | 328 | | |
325 | | - | |
| 329 | + | |
326 | 330 | | |
327 | 331 | | |
328 | 332 | | |
329 | | - | |
| 333 | + | |
330 | 334 | | |
331 | 335 | | |
332 | 336 | | |
| |||
1393 | 1397 | | |
1394 | 1398 | | |
1395 | 1399 | | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
1396 | 1404 | | |
1397 | 1405 | | |
1398 | 1406 | | |
1399 | 1407 | | |
1400 | | - | |
1401 | 1408 | | |
1402 | 1409 | | |
1403 | 1410 | | |
1404 | | - | |
| 1411 | + | |
1405 | 1412 | | |
1406 | 1413 | | |
1407 | 1414 | | |
| |||
1419 | 1426 | | |
1420 | 1427 | | |
1421 | 1428 | | |
1422 | | - | |
| 1429 | + | |
1423 | 1430 | | |
1424 | 1431 | | |
1425 | 1432 | | |
1426 | 1433 | | |
1427 | | - | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
1428 | 1437 | | |
1429 | 1438 | | |
1430 | 1439 | | |
| |||
1567 | 1576 | | |
1568 | 1577 | | |
1569 | 1578 | | |
1570 | | - | |
| 1579 | + | |
1571 | 1580 | | |
1572 | 1581 | | |
1573 | 1582 | | |
| |||
1593 | 1602 | | |
1594 | 1603 | | |
1595 | 1604 | | |
1596 | | - | |
| 1605 | + | |
1597 | 1606 | | |
1598 | 1607 | | |
1599 | 1608 | | |
| |||
1638 | 1647 | | |
1639 | 1648 | | |
1640 | 1649 | | |
1641 | | - | |
1642 | | - | |
1643 | | - | |
| 1650 | + | |
1644 | 1651 | | |
1645 | 1652 | | |
1646 | 1653 | | |
| |||
0 commit comments