-
Type:
Task
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: Performance, Query Execution
-
None
-
Query Execution
-
Fully Compatible
-
QE 2026-08-17, QE 2026-08-31
-
None
-
None
-
None
-
None
-
None
-
None
-
None
This change reorders the member variables of `SimpleMemoryUsageTracker` so that the most commonly accessed members all sit close together in the first 64 bytes.
It moves `_chunkSize` and `_lastReportedLowerBound` up in the struct, which in turn moves `_writeToCurOp` downwards.
Additionally it moves a `tassert` out of the hot path in `addInternal()` into a cold function `memoryTrackingUnderflowFailed()`, which is only called upon failure. It also moves the reporting to `CurOp` out of `addInternal()` into a separate function, which allows `addInternal()` to avoid much of its function prologue/epilogue.
It also improves the `if (current > peak)
{ peak = current; }` code by using `peak = std::max(peak, current);`, which may be performance-optimized better (branchless conditional store on an already loaded cache line).
The change also tries to avoid the expensive integer division for checking if the memory usage update crossed a boundary, which triggers reporting, into a simpler range comparison with the bounds in the optimal case.
Overall this should reduce the number of instructions for `addInternal()` from ~45 to around 30 using `opt` on arm64.
A new microbenchmark for memory usage trackers is added as part of this patch.
*Results (median real_time over 10 runs, ns/iteration; noise = worst per-side stdev/median):*
```
┌───────────────────────────────┬────────┬────────┬─────────┐
│ benchmark │ master │ branch │ delta │
├───────────────────────────────┼────────┼────────┼─────────┤
│ BM_AddZeroDelta │ 0.36 │ 0.36 │ +0.00% │
├───────────────────────────────┼────────┼────────┼─────────┤
│ BM_AddZeroDeltaChain │ 0.36 │ 0.36 │ -0.01% │
├───────────────────────────────┼────────┼────────┼─────────┤
│ BM_GroupAccumulatePattern/250 │ 0.76 │ 0.75 │ -1.06% │
├───────────────────────────────┼────────┼────────┼─────────┤
│ BM_GroupAccumulatePattern/10 │ 1.33 │ 1.07 │ -19.51% │
├───────────────────────────────┼────────┼────────┼─────────┤
│ BM_SetUnchangedTotal │ 1.80 │ 0.72 │ -60.21% │
├───────────────────────────────┼────────┼────────┼─────────┤
│ BM_AddNonZeroNoChunking │ 2.86 │ 2.51 │ -12.14% │
├───────────────────────────────┼────────┼────────┼─────────┤
│ BM_AddNonZeroCrossingChunk │ 5.77 │ 5.90 │ +2.24% │
├───────────────────────────────┼────────┼────────┼─────────┤
│ BM_AddNonZeroWithinChunk │ 6.44 │ 4.22 │ -34.50% │
├───────────────────────────────┼────────┼────────┼─────────┤
│ BM_GroupAccumulatePattern/0 │ 6.79 │ 4.30 │ -36.71% │
└───────────────────────────────┴────────┴────────┴─────────┘
```