Repository navigation
perf(sessions): reuse opaque-key matchers and pruning cursors - #133691
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 9:27 PM ET / August 31, 2026, 01:27 UTC. ClawSweeper reviewWhat this changesThe PR prepares fixed opaque-peer matchers once for session-key normalization and reuses one insertion-order iterator when pruning bounded maps. Merge readinessKeep open. The reviewed main context still has the pre-optimization implementation, while this small, maintainer-labeled PR makes behavior-preserving changes within the two owning helpers; no blocking correctness or security defect was found from source review. Priority: P3 Review scores
Verification
How this fits togetherSession-key normalization converts incoming channel and peer identifiers into stable storage and routing keys while preserving selected opaque IDs. Bounded-map pruning caps in-memory caches used by session and other runtime owners. flowchart LR
A[Channel and peer identifiers] --> B[Session-key normalization]
B --> C[Opaque peer preservation]
C --> D[Canonical session key]
E[In-memory cache entries] --> F[Bounded map pruning]
F --> G[Newest entries retained]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -10. Total -10 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the session normalizer and bounded-map helper as the sole owners of these operations, with the existing opaque-ID and cache-bound tests preserving their contracts. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR refactors existing internal work rather than reporting a user-visible failure. Is this the best way to solve the issue? Yes. Preparing the immutable matchers in the normalizer and retaining a cursor inside the map-pruning owner removes duplicate work without adding cache state or a parallel path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 119720344a87. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Session-key normalization rebuilt its fixed opaque-peer matchers for every uncached key, while bounded-map pruning restarted a keys iterator for each eviction. Both owners already have the information needed to avoid that work.
This prepares the existing matchers once, flattens their tail collector, removes a redundant normalization helper, and uses one insertion-order cursor for bulk eviction. The public normalizer and ordinary-key path stay unchanged, as do opaque Matrix/Signal bytes, thread suffixes, alias proof, cache bounds, TTL, and caller-owned Map lifecycle. There is no new cache, option, public API, persistence format, or authority policy. Production is +52/−62 lines (net −10); tests are unchanged.
All 176 existing session, routing, store-key, Map, dedupe, and directory-cache tests passed on current main and the candidate. Independent complete-owner review and managed Codex review found no actionable defects. The complete formatted production AST matches the measured proposal. Current-source review found only an unrelated redaction-pattern delimiter change among the 128 historical runtime inputs; package dependencies are unchanged since the previous source review. Historical measurements remain identified with their original base.
The retained differential proof covers 2,229 scenarios / 6,841 comparison units and 43 complete workload projections / 129 comparisons. Eight fresh forward/reverse processes retained all 3,784 timing samples. Uncached opaque-key normalization in an already loaded module improves about 2.1–2.3×, and pruning 2,048 entries while retaining 2,048 improves about 8.8×. Most callers evict only one entry. Costs remain explicit: ordinary mixed-case misses were 35/46 ns slower, empty dedupe insertion 9/24 ns slower, and one-item eviction at cap one 1/4 ns slower. Empty-store controls were order-sensitive. These are scoped owner measurements, not whole-Gateway, channel-delivery, provider, or memory gains.
Verification commands:
pnpm test src/sessions/session-key-case-preservation.test.ts src/routing/session-key.test.ts src/routing/session-key.continuity.test.ts src/config/sessions/session-key.test.ts src/config/sessions/explicit-session-key-normalization.test.ts src/infra/map-size.test.ts src/infra/dedupe.test.ts src/infra/outbound/directory-cache.test.ts -- --maxWorkers=1 pnpm check:changed --base d56aacd6991b4c552fe1bd71b3d061034a70906bFull changed-file checks passed, including production/test typechecks, lint, unused-export analysis, database guards, and zero runtime import cycles. This internal refactor preserves documented behavior; no new live-channel claim or operator action is introduced.