Skip to content

perf(kv-unified): pack labels and selectively rescore terminal cuts - #112

Merged
antra-tess merged 2 commits into
fix/kv-unified-general-solverfrom
fix/kv-unified-packed-selective
Sep 21, 2026
Merged

antra-tess merged 2 commits into
fix/kv-unified-general-solverfrom
fix/kv-unified-packed-selective

Conversation

@antra-tess

@antra-tess antra-tess commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Consolidated into #110 at 3356af7. GitHub marked this PR merged because its commits are now in #110's branch. Nothing has been merged into main; review and merge #110 only.

Problem

After #110, general solves still spend substantial time allocating/grouping labels and rescanning every leaf of every retained terminal cut. This implements the two follow-up leads: reusable packed propagation storage and selective exact terminal rescoring.

Changes

  • Use owned numeric label handles, contiguous binary64 records, immutable paged trace indices, and reusable generation-stamped bucket tables. Sparse fallback changes only storage, never pruning or stopping rules.
  • Cache action-level fidelity/continuity sums with conservative floating-point intervals; compute chronological cache costs exactly for every retained cut.
  • Establish exact normalization floors independently of welfare, then exactly rescore every possible winner, tie, and carried-layout contender. Preserve the existing comparator and hysteresis rule.
  • Preserve the complete sorted candidate API with deferred exact evaluation when the diagnostic list is requested. Keep storage: 'objects' and terminalEvaluation: 'full' as differential-reference modes.
  • Add storage/snapshot/bounds/tie/floor tests, per-estimate benchmark verification, replay reference checks, design notes, and a changelog fragment.

Policy weights, grids, hard walls, label ceilings, and adoption thresholds are unchanged. No solve deadline is introduced. All performance measurements disable the certificate.

Tests

  • npm run build: pass.
  • npm run typecheck: pass.
  • Full compiled Node suite: 822 pass / 0 fail, versus 813 / 0 on the fix(kv-unified): accelerate general solves and reduce memory use #110 parent; 9 added tests.
  • 90 varied forests: object/full, packed/full, and packed/selective have identical selected candidates, all retained candidates, floors, and pre-existing propagation/envelope statistics. Every feasible small cut is also checked against its bounds.
  • Saved 73,918-leaf / 3,345-summary fixture, fresh-process Bun runs:
Case Object/full Packed/selective Reduction
Warm cache, forced 500k wall 8.721 s 5.194 s 40.4%
Warm cache, newly pinned middle leaf 8.736 s 5.229 s 40.1%
Warm cache, 30k appended tail tokens 9.149 s 5.509 s 39.8%

All selected frontier hashes, scores, floors, and existing propagation/envelope statistics match exactly. Only 3 exact evaluations are needed in each case, versus 6,538–6,719 retained cuts (the count includes the feasibility-witness check). A separate diagnostic checked every pinned-case estimate against exact evaluation.

Controlled 500-message replay at 028b065: 500 successes / 0 failures, certificate disabled.

Statistic Previous replay Packed/selective Reduction
Mean 3.122 s 2.044 s 34.5%
Median 2.837 s 1.878 s 33.8%
p95 4.959 s 3.145 s 36.6%
p99 8.069 s 4.927 s 38.9%
Maximum 9.486 s 5.611 s 40.9%

420/500 solves are below 2 seconds, 495/500 below 5 seconds. All 23 exact-reference checks pass (warm-up, every 25th message, and every layout movement), including all four transitions. Checks compare frontier hashes, all selected loss terms, score, and both floors; reference time is outside the solve timer. Every row's tokens, movements, terminal labels, and maximum labels per state also match the old replay. The old rows lack hashes/scores, so this is not a claim of full decision comparison on all 500 historical rows.

The previous replay is the archived pre-rebase 5c55a26 run; a fresh complete #110-parent replay was not repeated. The paired large-fixture comparisons above use the current object backend. Replay timing includes forest/solver construction, solve, and selected frontier materialization; one warm-up is excluded. It models accepted layouts and fresh atomic cache markers using a frozen summary catalogue, not historical provider calls or cache TTLs. Observed high-water RSS was 3.285 GB including the in-process reference solves.

CI passes on macOS and Ubuntu with Node 20 and 24. Full design, reproduction steps, and validation details are in docs/kv-unified-packed-selective.md.

Not verified / out of scope

  • No live resident changes, deployment, provider calls, cache-TTL simulation, or historical compression reconstruction.
  • Local timings are measurements, not a universal runtime bound or a cross-platform guarantee.
  • Diagnostic candidate-list inspection intentionally performs remaining exact scoring; its cost is not eliminated.

Companion PRs

All changes are now incorporated into #110 without rewriting published history. This PR no longer needs separate review or merging.

🤖 Generated with Codex (GPT-6).

antra-tess and others added 2 commits September 21, 2026 12:08
… cuts

Preserve exact floors, selection, ties, and hysteresis while reusing bucket storage and avoiding unnecessary terminal leaf scans. Keep the object backend and exhaustive scoring as diagnostic references.

Co-Authored-By: Codex (GPT-6) <noreply@openai.com>
Co-Authored-By: Codex (GPT-6) <noreply@openai.com>
@antra-tess
antra-tess marked this pull request as ready for review September 21, 2026 19:28
@antra-tess
antra-tess merged commit afb5b4a into fix/kv-unified-general-solver Sep 21, 2026
5 checks passed
@antra-tess

Copy link
Copy Markdown
Contributor Author

Consolidated into #110 at 3356af7, preserving both commits and their validation history. GitHub marked this PR merged into its base branch; nothing was merged into main. Please review and merge #110 only.

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