Skip to content

fix(solver): keep required construction's buffers across placements - #286

Merged
blackopsrepl merged 1 commit into
mainfrom
fix/283-construction-allocations
Nov 30, 2026
Merged

blackopsrepl merged 1 commit into
mainfrom
fix/283-construction-allocations

Conversation

@blackopsrepl

Copy link
Copy Markdown
Collaborator

Follow-up to #285 (#283). Fixes the allocation regression #285 introduced.

Problem

#285 places required rows one move at a time. Every placement allocated its scratch again:

  • the augmenting search's blocker list, visited set and edit list;
  • each row's candidate values;
  • a fresh candidate store and target list;
  • the completed-slot set, and one probe placement per probed row;
  • the affected-row list of every grouped move.

The gate measured assignment_required against 0.31.4 at:

  • 496,897 allocations against 134,145 (+270%);
  • 52.7 MB allocated against 32.0 MB (+65%).

Change

The construction cursor owns those buffers and refills them:

  • Search scratch: the assignment state pools the blocker list and visited set; the move cursor keeps the edit list.
  • Candidate values: refilled into the cursor's own buffers (candidate_values_into, extend_candidate_values).
  • Placement buffers: the candidate store, targets, touched rows, completed slots and resume scratch travel with the generator through recycle.
  • Completion probes: done through one reusable placement (Placement::retarget).
  • Grouped moves: affected rows are iterated from the edits instead of a stored list, and a repeated row is caught by a scan instead of a hashed set.

Verification

One iteration of each case, against 0.31.4 (gate-smoke, shared bench source):

case metric 0.31.4 this PR
assignment_required allocations 4,193 3,698
assignment_required allocated bytes 1,000,709 478,017
assignment_required peak live bytes 360,984 240,620
assignment_neighborhood (4 iterations) allocations 206,448 180,248
assignment_neighborhood (4 iterations) allocated bytes 37,626,548 35,539,236
  • Output: both cases have the same order and identity hashes as 0.31.4.
  • make lint: passes.
  • make test: passed before two clippy-only edits; cargo test -p solverforge-solver --lib (818 tests) passes after them.
  • Full gate against 0.31.4: runs on merged main.

Placing required rows one move at a time (f4cc2fa) allocated again on
every placement: the augmenting search's blocker list and visited set, its
edit list, each row's candidate values, a fresh candidate store and target
list, the completed-slot set and one probe placement per probed row, and
the affected-row list of every grouped move. The gate measured
assignment_required at 496,897 allocations against 134,145 on 0.31.4
(+270%) and 52.7 MB against 32.0 MB allocated.

The construction cursor now owns those buffers and refills them:

- the assignment state pools the search's blocker list and visited set,
  and the move cursor its edit list;
- candidate values are refilled into the cursor's buffers
  (`candidate_values_into`, `extend_candidate_values`);
- the store, targets, touched rows, completed slots and resume scratch
  travel with the generator through `recycle`;
- completion is probed through one reusable placement (`retarget`);
- a grouped move iterates its affected rows from its edits instead of
  storing a list, and checks repeated rows by a scan instead of a set.

One iteration of assignment_required now allocates 3,698 times and
478,017 bytes (0.31.4: 4,193 and 1,000,709), peak 240,620 (0.31.4:
360,984), with the same roster; assignment_neighborhood allocates 180,248
times (0.31.4: 206,448) with the same candidates.
@blackopsrepl
blackopsrepl merged commit 29d7770 into main Nov 30, 2026
7 checks passed
@blackopsrepl
blackopsrepl deleted the fix/283-construction-allocations branch November 30, 2026 21:00
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