Skip to content

perf(csa): reuse compiled structured geometry in banking - #104

Merged
isty2e merged 2 commits into
mainfrom
perf/csa-compiled-geometry
Jul 28, 2026
Merged

perf(csa): reuse compiled structured geometry in banking#104
isty2e merged 2 commits into
mainfrom
perf/csa-compiled-geometry

Conversation

@isty2e

@isty2e isty2e commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • add a prevalidated encoding path to the built-in structured geometry plan
  • reuse immutable candidate encodings and operation-local distance workspaces across CSA admission, crowding, clustering, growth, removal, and average-distance queries
  • preserve the existing generic metric path for custom metrics and keep the bank as the authoritative state
  • harden workspace alignment so replacement, removal, index remapping, or foreign geometry plans cannot retain stale distances

This avoids repeatedly validating and encoding stable bank entries. The derived geometry view is not shared between studies, persisted in checkpoints, or exposed as mutable optimizer state.

Performance

Same-process benchmarks used 600 CSA steps, a bank capacity of 24, and seven repetitions. Compiled and fallback runs produced identical final states.

Workload Generic fallback Compiled geometry Speedup
16-element integer array 0.153938 s 0.138967 s 1.108x
Mixed record 0.194265 s 0.145373 s 1.336x
Mixed-record clustering 0.156043 s 0.118463 s 1.317x

Instrumentation on a 300-step integer-array run recorded 5,880 batched distance calculations instead of 9,016 public metric calls. Validation calls remained unchanged at 604, while traced peak allocation decreased from 232,101 to 169,333 bytes. The instrumented runs were used for call and allocation attribution, not for the wall-time claim above.

Correctness

The test coverage exercises append, replacement, removal, growth, clustering, equality-hostile candidates, stale and foreign views, invalid indices, cutoff boundaries, pickle round trips, and checkpoint continuation. A 48-step compiled-versus-fallback trajectory test compares every resulting optimizer state.

No public symbols, dependency requirements, or checkpoint schema were added or changed.

Verification

  • uv run pytest -q (1598 passed)
  • focused CSA, checkpoint, exact-async, and geometry suite (231 passed)
  • uv run ruff format --check src tests .github/scripts
  • uv run ruff check .
  • uv run basedpyright src tests .github/scripts (0 errors, 0 warnings, 0 notes)
  • uv run mkdocs build --strict
  • targeted Zuban checks for the changed typed boundaries

@isty2e
isty2e merged commit 46c1cbf into main Jul 28, 2026
8 checks passed
@isty2e
isty2e deleted the perf/csa-compiled-geometry branch July 28, 2026 01:23
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