Skip to content

perf(solver): keep cartesian and list kernel tables across steps (#283) - #290

Merged
blackopsrepl merged 2 commits into
mainfrom
fix/283-cartesian-capacity
Dec 1, 2026
Merged

blackopsrepl merged 2 commits into
mainfrom
fix/283-cartesian-capacity

Conversation

@blackopsrepl

Copy link
Copy Markdown
Collaborator

Fixes the failures of the zero-regression gate of main (2f9aadf) against v0.31.4:

case metric v0.31.4 main delta
cartesian sim_d1_misses 1.63M 3.45M +112%
cartesian sim_ll_misses 16.6k 20.1k +21%
k_opt sim_d1_misses 387k 408k +5.5%
scalar_change wall_ns 17.18 ms 18.73 ms +9.1%

#289 shrank the grouped leaf cursor, which moved the heap layout of every local-search case. Cartesian and the list kernels rebuilt per-step lists from empty and regrew them by reallocation; whether a reallocation extends in place depends on its heap neighbours, so after the layout change more of them copied. On identical code, moving the heap start by 0-3584 bytes left main in the worse mode on 7 of 8 offsets, so the fix is in the cursors, not in the gate's sampling.

  • The cartesian cursor allocates its row and pair lists once, at the last step's sizes.
  • The list leaf's stream state keeps each slot kernel's candidate-ID table and the slot union's discovered table across steps, as the local-search leaf already does for its own table.

Cachegrind, one layout against v0.31.4 (sim D1 misses / instructions):

case v0.31.4 this PR instructions
k_opt 388051 177635 -2.4%
list_change 5943680 2871081 -1.6%
union 14367383 6954045 -1.7%
cartesian 1619900 1353503 -0.9%
scalar_change 154388 153987 -1.1%
ruin 820506 819644 -0.2%

Allocation smoke on 16 cases against v0.31.4: identical order hashes, and allocations, allocated bytes and peak live bytes at or below v0.31.4 on every case (e.g. list_change 60 / 27432 / 6762 against 188 / 33583016 / 4201482).

scalar_change on a quiet core (perf stat -r 20, three rounds): 74.4-75.5 M cycles against v0.31.4's 74.7-77.2 M.

make lint and make test pass. The full gate runs on merged main.

…ast step

The cartesian cursor rebuilt its row and pair lists from empty on every
step and grew them by reallocation. Whether a reallocation extends in place
depends on what the heap holds next to it: after #289 shrank the grouped
leaf cursor, the cartesian gate case's reallocations moved instead of
extending, and its simulated data-L1 misses rose +112% against v0.31.4 with
equal allocation counts.

The composition stream state keeps each cartesian node's last row and pair
counts, and the next step's cursor allocates both lists once at that size.

cartesian, one layout against v0.31.4: sim D1 misses 1353503 (1619900),
instructions -0.9%, allocated bytes 2491972 (5193284), peak 278866 (481042),
identical order hash.
Every list neighborhood step opened its slot kernels with empty candidate
stores and an empty union table and regrew them one candidate at a time;
k-opt and the full list neighborhoods enumerate thousands of candidates per
step, so most of their data-L1 misses were reallocation copies of those
tables. After #289 changed the heap layout the k_opt gate case moved more of
them and failed sim_d1_misses at +5.5% against v0.31.4.

The list leaf's stream state keeps each slot kernel's candidate-ID table and
the slot union's discovered table; the step's cursor takes them on open and
the local-search leaf hands them back on close, as it already does for its
own table.

One layout against v0.31.4 (sim D1 misses, instructions):
k_opt 177635 / 388051, -2.4%; list_change 2871081 / 5943680, -1.6%;
union 6954045 / 14367383, -1.7%. Allocation smoke (4 iterations, identical
order hashes): list_change 60 allocations / 27432 bytes / 6762 peak
(188 / 33583016 / 4201482); k_opt 5492 / 222184 / 6658 (5588 / 2320488 /
269218).
@blackopsrepl
blackopsrepl merged commit 3a55af5 into main Dec 1, 2026
7 checks passed
@blackopsrepl
blackopsrepl deleted the fix/283-cartesian-capacity branch December 1, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant