Skip to content

fix(solver): index pending assignments by key in the path overlay - #284

Merged
blackopsrepl merged 2 commits into
mainfrom
fix/283-required-batch-overlay-index
Nov 30, 2026
Merged

blackopsrepl merged 2 commits into
mainfrom
fix/283-required-batch-overlay-index

Conversation

@blackopsrepl

Copy link
Copy Markdown
Collaborator

The required batch of a grouped-scalar assignment construction was quadratic in its required rows. On INRC-II n120w8 it took 1.3 s, so a 1-second solve stopped inside it and kept none of its placements (2844 / 2872 required rows unassigned). Closes #283.

Cause

The first bad commit is 3992802 (0.20.4), bisected commit by commit with the bench NRP adapter built against path dependencies. Its parent d2b3c2d solves both instances at 1 s; 3992802 fails both 3/3. The issue's earlier 0.20.0 boundary came from cargo update -p solverforge --precise 0.20.0, which leaves solverforge-solver on 0.20.4 because the facade then depended on its sub-crates by caret version.

3992802 moved the batch onto AssignmentPathOverlay, which keeps one pending row per placed required entity. blockers and collect_members scanned every pending row on every query, which made the batch quadratic. A profile of 3992802 on H0: 62% collect_members, 26% blockers.

Fix

  • Every pending assigned row is linked into an intrusive chain for its capacity key and its (value, sequence) coordinate. Queries walk one chain. The head maps are boxed and allocated on first link. Rule members are iterated instead of collected, so the overlay struct shrinks from 104 to 64 bytes.
  • The required batch reserves the overlay for its required rows and releases it before final validation. It drops edited_entities: a depth-0 discovery that yields one edit always assigns the still-unassigned root, so the check never fired.

Semantics are unchanged. Blockers and the rule verdict are compared with a full-scan oracle across 64 seeded sequences of set, checkpoint, rollback and clear (indexed_overlay_blockers_match_full_scan_oracle_across_rollbacks). required_batch_key_work_grows_linearly_with_required_rows fails on main: key hook calls grow from 67,072 at 256 rows to 1,054,720 at 1024 rows.

Gate cases

There was no gate case for grouped-scalar assignment, so the first commit adds two, registered in the script and AGENTS.md:

  • assignment_required: the default runtime's required batch on a 504-shift roster
  • assignment_neighborhood: the compiled grouped-scalar local-search neighborhood over that roster, including augmenting-path repairs. The path overlay accounts for about 19% of its profile.

Shared-source smoke against main, 32 iterations:

case identical wall allocations allocated bytes peak live bytes
assignment_required yes (roster hash) -96.8% -0.53% -1.35% -10.1%
assignment_neighborhood yes (order hash, 2016 candidates) -1.6% 0.00% -0.001% -0.002%

Verification

  • make lint: passed (fmt, clippy all targets, doc-names, file-length, facade, public-api, deps)
  • make test: passed
  • n120w8 H0 and H1 at 1 s through the bench adapter: required batch 1334 / 1416 ms → 60 ms; both feasible, 0hard/-225715soft and 0hard/-227785soft (0.19.13: -227645 / -228870)
  • Not run yet: the full zero-regression gate against v0.31.4. It runs on merged main before the next release.

The zero-regression gate had no case for grouped-scalar assignment groups,
so the dense required batch and the grouped local-search neighborhood ran in
production without a performance guard.

assignment_required solves a rostering-shaped assignment group (504 required
shifts, one shift per nurse per day, a late-to-early succession rule) with
the default runtime, which commits the dense required batch. The cross-tree
order hash is the constructed roster.

assignment_neighborhood enumerates the compiled grouped-scalar local-search
neighborhood of the same group over that roster, including the
augmenting-path repairs.
The required batch keeps one pending row per placed required entity in the
path overlay, and every blocker and rule-member query scanned all pending
rows. The batch was quadratic in the required rows: on INRC-II n120w8 it
took 1.3 s, so a 1-second solve stopped inside it and kept none of its 2844
or 2872 placements. The scan came in with 3992802 (0.20.4).

Pending assigned rows are now linked into intrusive chains per capacity key
and per (value, sequence) coordinate; queries walk one chain. Rule members
are iterated instead of collected. The batch reserves its overlay for the
required rows and releases it before final validation, and drops the
edited-entity set, which a depth-0 discovery could never hit.

Blockers and verdicts are unchanged: a seeded differential test compares
them with a full-scan oracle across set, checkpoint, rollback and clear
sequences, and the constructed roster is identical on both trees.

assignment_required: 30x faster, allocations -0.5%, bytes -1.3%, peak -10%.
assignment_neighborhood: wall -1.6%, allocations equal, bytes and peak lower.
n120w8 H0/H1 at 1 s: required batch 1334/1416 ms -> 60 ms, both feasible.

Closes #283
@blackopsrepl
blackopsrepl merged commit 9ab0b17 into main Nov 30, 2026
7 checks passed
@blackopsrepl
blackopsrepl deleted the fix/283-required-batch-overlay-index 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.

NRP n120w8: 1-second solves leave mandatory shifts unassigned since 0.20.0

1 participant