Skip to content

perf: rescore only changed list-shadow rows and recreate grouped ruins in one pass - #275

Merged
blackopsrepl merged 3 commits into
mainfrom
perf/list-shadow-rows
Nov 17, 2026
Merged

blackopsrepl merged 3 commits into
mainfrom
perf/list-shadow-rows

Conversation

@blackopsrepl

@blackopsrepl blackopsrepl commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Grouped ruin-and-recreate on a route model was about 10× slower per move than single-element ruin was on 0.30. The zero-regression gate never ran that code: its cases only generate candidates, against an empty constraint set, and none declares element groups or list shadows. This PR adds cases that execute moves against a scored route model, then removes the two costs those cases expose.

Commits

  1. test(bench): gate route rows and grouped ruin-and-recreate moves
    • A hand-declared route model: pick-up/drop-off pairs as element groups, list shadows, a cascading arrival time, and late, split-pair, load and arrival constraints over every stop row.
    • route_rows: list changes through the score director.
    • group_ruin: the compiled grouped ruin neighborhood; each candidate is done, scored and undone.
    • Both are added to the default cases.
  2. perf(scoring): rescore only the list-shadow rows a cascading move changes
    • With a cascading shadow, every owner change retracted and re-inserted every element row of that owner, so one insertion rescored the whole route.
    • The director now retracts only:
      • elements whose structure shadows don't already describe their new place;
      • arrivals from no list;
      • elements left in no list;
      • elements whose cascading value changes.
    • The new PlanningSolution::list_structure_unchanged hook answers the structure question from the element's own shadow fields before they are rewritten. The director therefore keeps no per-element record, and peak live bytes go down.
    • The macro generates the hook. The default (false) keeps the old behaviour for hand-written solutions.
  3. perf(list): recreate ruined groups in one pass with shared trial prefixes
    • Recreate searched every remaining unit in every round and committed only the best one: k(k+1)/2 searches for k units.
    • Each trial inserted and removed all members in two owner changes.
    • Recreate now does one pass in the plan's order, which is the standard ruin-and-recreate order.
    • A placement search keeps the members in the list between trials. It moves only the members after the shared position prefix, in one owner change per trial.

Measurements against v0.31.0

Gate smoke, shared-source mode, candidate built with --features candidate:

case wall allocations peak live bytes scores
route_rows (2 passes) 96 ms → 57 ms 492k → 262k 107,632 → 96,256 identical (identity hash equal)
group_ruin (2 passes) 1,361 ms → 107 ms 6.58M → 443k 107,660 → 107,636 recreate order changed by design

On a real model (pick-up and delivery routing, Milan demo with 155 jobs on 30 shifts, 60 s solves, 3 runs each), only commit 3 applies, because that model does not use cascading shadows yet:

unplanned mandatory stops soft moves/s
v0.31.0 26 / 16 / 32 −271k to −277k 1.5k–2.0k
this branch 10 / 8 / 10 −250k to −256k 3.1k–3.5k

Tests

  • New director test: appending a task to a route rescores only the two rows whose shadows change. It fails on v0.31.0 with 14 row weighings.
  • The existing cascading tests, joint-cascade tests and element-group tests (including full_assert solves) pass.
  • make lint passes (public API blessed: PlanningSolution::list_structure_unchanged).
  • cargo clippy --workspace --all-targets --all-features -D warnings passes.

Zero-regression gate

Qualifying run on bfd0ef4a against v0.31.0, covering all default cases plus the two new ones: passed, with semantics matching on every case.

  • group_ruin: wall −91.0%, instructions −91.2%, allocations −92.5%.
  • route_rows: wall −40.3%, instructions −39.8%, allocations −46.7%, peak live bytes −10.6%.
  • Every other case: instructions and allocations ±0.0%, wall within ±1.5%.

The zero-regression gate generated candidates only, against an empty constraint set, and no case declared element groups or list shadows, so neither the score director row maintenance of a route model nor the joint recreate of grouped ruin moves was measured. route_rows changes routes of a model with cascading arrival times through the director; group_ruin does, scores and undoes the compiled grouped ruin candidates. On v0.31.0 one grouped ruin move of a 12-vehicle, 20-stop route costs about 200 ms.
…nges

With a cascading shadow, every owner change retracted and re-inserted the row of every element the owner held, so one insertion into a route rescored the whole route. The director now records the elements of each notified owner without retracting them, and after the change retracts only elements whose structure shadows do not already describe their new place, arrivals from no list, elements left in no list, and elements whose cascading value changes. The new PlanningSolution::list_structure_unchanged hook answers the structure question from the element's own shadow fields before they are rewritten, so the director keeps no per-element record; #[shadow_variable_updates(cascading_field = ...)] generates it, and the default (false) keeps the previous behaviour for hand-written solutions.

route_rows against v0.31.0: 96 ms to 57 ms, allocations 492k to 262k, peak live bytes 107,632 to 96,256, identical scores on all 4,096 changes.
…ixes

Grouped ruin recreate searched every remaining unit's joint placements in every round and committed only the best, about k(k+1)/2 searches for k units, and each scored placement inserted and removed every member in two owner changes. Recreate now places the units in one pass in the plan's order, each at its best placement given those before it, the standard ruin-and-recreate order. A placement search keeps the unit's members in the list between trials and moves only the members after the positions consecutive placements share, in one owner change per trial.

group_ruin against v0.31.0 (with the row change): 1,361 ms to 107 ms for two passes, allocations 6.58M to 443k.
@blackopsrepl
blackopsrepl merged commit 31a9e13 into main Nov 17, 2026
7 checks passed
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