Skip to content

perf(registry): reduce scan allocation and duplicate evidence work - #1341

Closed
Gajesh2007 wants to merge 2 commits into
Layr-Labs:masterfrom
Gajesh2007:codex/registry-hot-path-optimization
Closed

Gajesh2007 wants to merge 2 commits into
Layr-Labs:masterfrom
Gajesh2007:codex/registry-hot-path-optimization

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Fleet reservation scans retain full admission snapshots, repeatedly copy forecast evidence, and repeat pending/service and alternate projections. This reduces that work through bounded private storage reuse, compact detached candidates, borrowed immutable inputs, one pending/service projection per locked snapshot, and one alternate selection projection. The locked current-state admission and pending debit remain atomic.

All five optimization areas are implemented and measured together. Candidates fall from 1,448 to 592 bytes. Public/decorated preparations retain owned storage; private reuse starts only after copying the model index and ends after copied decisions/plans are assembled. Indexed scans above 3,520 providers use owned storage immediately; retained objects are limited to 64 chunks (approximately 2 MiB per object, without a global pool cap).

Six alternating fresh-process pairs (Go 1.25.0, 700 ms/case, 12 workers) improve all 23 measured workloads in every paired round against master. The standard 350-provider reserve goes 313.661 → 267.959 µs (-14.57%), with 435,152 → 8,370 B/op (-98.08%) and 19 → 6 allocations. Unique-ID parallel improves 23.36%, writer-loaded parallel 26.29%, eight-alternate planning 19.51%, and busy pending/service cases 24.03–29.84%. Scale and skew cases improve 14.75–25.11%; capacity preflight improves 7.36%.

A separate fair three-variant block shows 337.538 → 269.058 µs versus master (-20.29%), while optimized routing remains 24.32% slower than the older pre-#1324 revision (216.425 µs). Results are per-block medians, not summed prototype gains. The selected oversized fallback avoids a measured 1.73% mixed narrow/large scan slowdown from always borrowing; allocation and latency tradeoffs are documented.

Before

flowchart TD
  B0([Request]) --> B1["Scan indexed providers / registry read lock"]
  B1 --> B2["Retain full Candidate snapshots; allocate chunks"]
  B2 --> B3["Copy forecast evidence; repeat pending/report work"]
  B3 --> B4["Rank and select"]
  B4 --> B5["commitProviderReservation: revalidate / admit / debit"]
  B5 --> B6(["Reserved provider / detached decision"])
  B5 --> B7["Repeated alternate projection"]
  B7 --> B8(["DispatchPlan: revalidate each later debit"])
  B1 --> B9(["No feasible provider: existing retry / failure policy"])
  classDef entry fill:#dbeafe,stroke:#2563eb,color:#172554
  classDef work fill:#fef3c7,stroke:#d97706,color:#451a03
  classDef safety fill:#dcfce7,stroke:#16a34a,color:#14532d
  classDef failure fill:#fee2e2,stroke:#dc2626,color:#450a0a
  class B0 entry
  class B1,B2,B3,B4,B7 work
  class B5,B6,B8 safety
  class B9 failure
Loading

After

flowchart TD
  A0([Request]) --> A1["Copy index / choose private or owned arena"]
  A1 --> A2["Reuse transient routingSnapshot; retain compact values"]
  A2 --> A3["Freeze pending once; validate owner-bound report once"]
  A3 --> A4["Borrow evidence; unchanged rank and selection"]
  A4 --> A5["commitProviderReservation: revalidate / admit / debit"]
  A5 --> A6(["Reserved provider / detached decision"])
  A5 --> A7["RetainRanked: project once / rerank after removal"]
  A7 --> A8(["DispatchPlan: revalidate each later debit"])
  A6 --> A10["Clear historical private chunks / return bounded storage"]
  A8 --> A10
  A1 --> A9(["No feasible provider: existing retry / failure policy"])
  A9 --> A10
  classDef entry fill:#dbeafe,stroke:#2563eb,color:#172554
  classDef work fill:#e0e7ff,stroke:#4f46e5,color:#1e1b4b
  classDef safety fill:#dcfce7,stroke:#16a34a,color:#14532d
  classDef failure fill:#fee2e2,stroke:#dc2626,color:#450a0a
  class A0 entry
  class A1,A2,A3,A4,A7,A10 work
  class A5,A6,A8 safety
  class A9 failure
Loading

Blue marks incoming work, amber/indigo scan work, green the preserved admission/debit and returned values, and red the existing failure policy. Return/reset follows synchronous consumption; public scans and decorated preparations never borrow private candidate storage. A later dispatch-plan claim uses copied evidence and current locked revalidation.

Validation

Cached pinned Go 1.25.0, isolated checkout, offline modules and empty database environment:

  • python3 scripts/run-coordinator-tests.py --jobs 2: all 21 jobs pass; 91 tested packages, 4,298 top-level passes, 111 top-level skips; 114.405 seconds.
  • go test -race ./coordinator/tests/registry/... -count=1 -v: eight packages pass, 1,512 top-level passes, no race report.
  • go vet ./coordinator/..., make coordinator-build coordinator-build-linux, and python3 scripts/test-coordinator-tests.py: pass.
  • Selection differential: 2,096 cases and 10,258 valid decisions, unchanged digest; retained alternate differential: 864 cases with identical order/draw traces.
  • 73 held public quotes, a public preparation and copied eight-entry plan survive 160 concurrent unique private reservations in ordinary/decorated modes. Hard storage bounds, rejected-slot clearing, independent fail-open passes, overflow ownership and 3,520/3,521/3,520 model-index boundaries pass.
  • Pending/service tests cover owner/UUID/finite-usage bounds, 17-item spill, committed-content output work, retained memory and exact admission/retirement. Successful calibration preserves borrowed evidence.
  • make docs-impact-check BASE=origin/master and make docs-check: pass; impact coverage complete and 331 documents lint clean.

The required dedicated refactor subagent removed the obsolete private preparation wrapper chain; focused race checks and final combined checks passed afterward. A separate independent correctness reviewer found no actionable introduced defect in the final coordinator diff. No HTTP/protocol/config/migration/ledger changes.

The full local suite skips PostgreSQL cases without an installed database and credentials-dependent/provider E2E was not run. The default host Go 1.27.1 has existing JSON parity failures on both original head/base; acceptance uses pinned Go 1.25.0. Local microbenchmarks do not predict production first-content or inference latency. Parallel ns/op is aggregate throughput, not per-request latency; writer maxima are noisy. Normal exact-head CI, automated review and protected E2E gates remain required before merge.

Canonical mechanism docs and the full combined measurements are in the measurement report.

Both PR commits are GitHub Verified (valid), published through GitHub's signed commit API. Initial implementation 122b5eed47d605c0cce09cd2b45c8239df32229c has reviewed master c5552d3af7ae725f956a2911b44d3e933da4b94c as its sole parent. Latest head f3233beca292dc6385148623a75a3bc6b4c3b8e5 removes four unused legacy snapshot helpers found by CI and updates stale comments; active decode-floor, live TTFT and shadow paths are unchanged. An independent reviewer approved the cleanup. Post-cleanup full registry race checks pass across eight packages (1,513 top-level tests), along with coordinator vet, macOS/Linux builds and docs checks. Latest remote tree 586f2b3b4300500403c7e507c417eb5944ca8cc8 exactly matches the locally validated tree. Timing samples preceded this behavior-preserving deletion; exact latest-head CI and integration remain separate merge gates.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Reuse bounded private candidate storage, retain compact detached evidence, borrow forecast inputs, project alternates once, and aggregate pending/service evidence. Preserve public quote ownership and locked reservation admission/debits. Include differential/lifetime/boundary tests and measured local validation.
@vercel

vercel Bot commented Oct 4, 2026

Copy link
Copy Markdown

@Gajesh2007 is attempting to deploy a commit to the EigenLabs Team on Vercel.

A member of the Team first needs to authorize it.

@Gajesh2007
Gajesh2007 marked this pull request as ready for review October 4, 2026 23:16
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head f3233beca292 against base c5552d3af7ae.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
Ten-PR pilot complete; maintainer evaluation required

Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging.

Coverage: 0/0 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned.

Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens.

Saved findings and earlier report · Historical findings are not confirmed resolved.

Remove unused routingSnapshot decode and shadow-TTFT wrappers after compact candidate snapshots took over their callers. Preserve live admission and shadow behavior; update comments and measurement provenance.

Validated full registry race suite, coordinator vet, macOS and Linux builds, docs impact and docs lint.
@Gajesh2007

Copy link
Copy Markdown
Member Author

Superseded by #1345 at the author's request. The head branch now lives in Layr-Labs/d-inference (codex/registry-hot-path-optimization), not the personal fork. Both signed cleanup histories are preserved, including f3233be, and current master bc1ee16 is merged. Independent correctness/structure reviews, full coordinator tests, registry race tests, lint, native/Linux builds, and docs checks passed. Exact-head CI continues on #1345. The personal branch is preserved.

@Gajesh2007 Gajesh2007 closed this Oct 4, 2026

This branch was successfully deployed

No deployments
benchmarks — f3233bec Deployed Oct 4, 2026 by Gajesh2007 via E2E Benchmarks #2213
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