fix(optimizer): recall-SLA-aware topk bind — CMS-heap when recall is loose (~60× cheaper) - #371
Merged
Merged
Conversation
The Fig-12 harness flagged a P95 cost-gap tail: BindCountSketchOnTopK
hard-bound every non-exact top-k to CountSketch (~250 KB wire state)
when a Count-Min-with-heap (~4 KB) answers approximate heavy-hitter
queries fine under a loose recall SLA — ~66x more expensive than
necessary.
Make the top-k binding recall-tier-aware and cost-aware:
* Loose recall (recall@k >= ~0.9, no signed/exact-rank need; the
common case) -> CMS-with-heap (cheap, one-sided over-estimate).
* Tight recall (exact rank / signed / two-sided) -> CountSketch-
with-heap (unbiased median-of-rows).
The tie-break among families that meet the SLA uses the existing
optimizer::cost::wire cost table — the same "min cost s.t. SLA" the
oracle uses; for a loose SLA both clear the bar so the cheaper CMS-heap
wins. The CMS-with-heap emit path is already servable end-to-end
(stage_config promotes with_heap to CountMinSketchWithHeap;
asap_tier_analysis maps it to FrequencyTopk(CmsWithHeap)).
No per-query recall field exists yet, so the tier is inferred from the
accuracy target (Exact -> Tight, else Loose); threading a real per-query
recall@k target is the follow-up. bind_workload_typed keeps its pinned-
family routing via the new apply_with_tier entry point (CountSketch pick
-> Tight, CMS-on-topk pick -> Loose), so contract-row mappings are
unchanged. The redundant bind_cms_with_heap_on_topk helper is removed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Fig-12 harness found the optimizer hard-binds topk → CountSketch (~250 KB wire state) where a CMS-with-heap (~4 KB) answers approximate heavy-hitter queries fine under a loose recall SLA — ~60× more expensive than necessary (the harness P95 cost-gap tail).
Fix (
sketch_algebra/rules/bind_cms_topk.rs):BindCountSketchOnTopKis now recall-tier-aware — Loose →{CMS-heap, CountSketch}, Tight →{CountSketch}— with a cost-min tie-break over the SLA-meeting set (the same min-cost-s.t.-SLA the oracle uses). Loose-recall topk → CMS-heap; exact/tight → CountSketch (unbiased).bind_workload_typedroutes pinned picks via the newapply_with_tier.Cost: loose-recall topk drops 250,200 → 4,200 B/flush (~59.6×), from the optimizer's own
wire.rstable.Recall source: no per-query recall field today (
AccuracyTargetis a frequency budget) → tier inferred conservatively (Exact→Tight, else Loose=cheap). Follow-up: thread a realrecall@k/signedtarget. Servability confirmed end-to-end (Cms{with_heap} → FrequencyTopk).Tests: 3 new (loose→CMS-heap, tight→CountSketch, cost-min pick) + fixed the old hard-bind test.
cargo build/test -p control_planegreen except one pre-existing unrelated failure (invalid_sketch_type_override_falls_back_to_default, verified on main via git stash).🤖 Generated with Claude Code