Repository navigation
[PR] perf(registry): index relay model suffix candidates - #7285
ranxianglei merged 1 commit into
Conversation
(ai: opencode/vllm-qwen/qwen3.8-27b) 查重: 不重复. Same performance domain as the open #7279 (billing-row normalization) and #7282 (cost-index cache eviction), but a different mechanism: those fix repeated normalization and alternating-table index eviction; this PR removes the per-lookup O(n) suffix row scan itself, which neither of them touches. Source issue #7284 states the distinction explicitly. No other open PR targets the suffix scan. 标签: #7284 labeled Review — independent verification performed
结构化八问
判定: 可合(human merge)—— |
(ai: opencode/vllm-qwen/qwen3.8-27b) CI status update (live-verified): the full CI run on the pushed head Updated verdict: 可合 (mergeable) — full regression green on the pushed head; human merge per §7.4 ( |
Fixes #7284.
Problem and change
Relay lookup scans all lowercase-index entries for each model suffix even when the underlying registry is unchanged. Repeated pricing/context/output queries therefore keep walking the entire roster for a small matching subset or a missing model.
Build suffix buckets once, lazily on the first relay fallback. Index every slash boundary so nested model ids retain the existing matching behavior. Buckets preserve
Object.entriesorder and all case-collision rows; exact keys, known-provider precedence, variant order, first usable price, maximum context/output ceiling and conflict-warning order stay unchanged. The suffix map lives with the existing identity-checked table index and is rebuilt when that index is replaced. Its entries share the same immutable row records as the lowercase map.This targets the remaining suffix scan, independently of #7279's billing-row normalization and #7282's two-table cache. No kernel, request-wire, configuration, persistence or model-facing text changes.
Validation
Base:
04ecbb42dd38543e9c407bd40eb773ae5ec8b60b, still current upstream master at publication. Commit:cee5b4e08100a5a3d54f5c666a82413b845d08ca.npm run typecheck,npm run build(including the kernel/pi-subagents builds and dist checks), andgit diff --checkpassed.The full regression verdict remains the upstream CI on the pushed head.
Measurements and cost
The included
scripts/bench-registry-suffix-index.tsuses the real bundled 7,126 cost rows and 428 model entries, no network. Each measured iteration resolves pricing, context and output. Each case warms 5,000 iterations before measuring another 5,000. Four isolated processes ran before/change/change/before, pinned to one CPU on Linux with Node.js 24.22.3. Output arrays are SHA-256 hashed after timing.All four real-model output hashes are
7aeaa317ff2464199514139965e687d41566318002a77381b9ed73fc9b3ad7de; all missing-model hashes are93a07756a5faaa16afac511398bdccefff61bcd36003e5ca0fcfc2e8292eac1b.There is a storage/setup tradeoff. After explicit GC, the measured indexes retain about 0.4 MB more heap for this roster (roughly 1.2–1.4 MB before versus 1.6–1.8 MB after). First-lookup construction is outside the steady-state measurement: the real-model case ranged 16.4–44.5 ms before and 29.0–31.5 ms after; the missing-model case ranged 15.6–17.5 ms before and 20.1–23.0 ms after. Exact/provider-only lookups do not allocate the suffix buckets. Timings vary on this shared host; no proportional end-to-end request speedup is claimed.
Reproduce from either revision, copying the benchmark to the baseline when comparing: