Skip to content

feat(gos): DDSketch sparse wire fix + insert-time delta gate (T=εN/(kB)) - #528

Merged
zzylol merged 1 commit into
mainfrom
split/pr-gos-ddsketch
Jul 17, 2026
Merged

zzylol merged 1 commit into
mainfrom
split/pr-gos-ddsketch

Conversation

@zzylol

@zzylol zzylol commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Part of the GOS per-family stack (base: CountSketch split/pr-gos-countsketch / #524). Depends on sketchlib-go #75 (sparse full-snapshot wire fix + UpdateGOS/PopulatedBuckets).

Converts DDSketch's delta gating to insert-time detect+reset (design §11). Formula T=εN/(kB) (derivations §8.4), with B (populated-bucket count) tracked EXACTLY via first-touch increment / reset decrement — never assumed, since an assumed B<B_actual doesn't just loosen but VIOLATES the staleness bound. DDSketchWrapper: SetGosMode, DDSketchIsotropicThreshold, dirty-list + one-shot wake, drainGosDelta wired into ComputeDeltaAgainst; SketchTypeDDSketch branches in subWindowShouldEmit/subWindowMarkEmitted; factory priming; gos_delta_epsilon accepted for family=ddsketch.

Known interaction with sampling PR #518 (flagged for #518's reattachment, not a blocker here): #518 adds a row-admission path (ApplyAdmittedOccurrence) that bypasses GOS detection — a DDSketch with both sampling and gos_delta_epsilon>0 would silently skip insert-time detection. Composing them is #518's job when it rebases onto this stack; estimates stay unbiased.

Cross-repo follow-up (from the sketchlib-go half): the Rust backend (ASAPQuery-backend) needs a decoder update for the new sparse buckets proto field before it can read sparse-encoded outlier sketches (until then they decode as empty there — still strictly better than a multi-GB dense alloc).

Test plan

  • wrapper: empty-drain→nil, wake-fires-once, telescoping; sketchlib: disabled/crossing+reset/first-touch-B/telescoping + sparse-outlier wire regression.
  • processor: TestGOSDDSketchInsertWakesFlush + per-family validation matrix.
  • build/vet/test clean in all three locations.

🤖 Generated with Claude Code

Converts DDSketch to the GOS insert-time delta mechanism, following the
CountSketch precedent (commit 9a0b401). Instead of the periodic
decode-prev-snapshot-and-diff sub-window scan, each bucket touch now
checks its own accumulated-since-last-send count against a closed-form
threshold; on crossing, the value is captured as the delta, the bucket
is reset to 0 in place, and the flush loop is woken immediately.

DDSketch's CDM isotropic threshold (derivations §8.4) is the L1
value-range-count form T=ε·N/(k·B), where N is the sketch's total
count and B is the number of POPULATED buckets. B is read from
sketchlib-go DDSketch.PopulatedBuckets() — tracked incrementally and
exactly (first-touch increment / reset decrement), never assumed:
the derivation is explicit that understating B silently VIOLATES the
staleness guarantee (scales as ε·N·(B_actual/B_assumed), only bounded
when B_assumed >= B_actual), so an assumed constant is not safe.

Changes:
- sketches/gos_threshold.go: DDSketchIsotropicThreshold (T=ε·N/(k·B)),
  alongside the existing CountSketch F2IsotropicThreshold; returns +Inf
  for B==0 so cold start (N=0,B=0) falls through to the caller's
  floor-at-1 (ship-on-first-touch) — "cold start is a feature".
- sketches/ddsketch.go (DDSketchWrapper): SetGosMode, GosDeltaThreshold,
  a dirty-list + one-shot wake signal (recordDirty/ConsumeWakeSignal),
  and drainGosDelta wired into ComputeDeltaAgainst — the GOS branch
  drains the insert-time dirty list into a proto DDSketchDelta and never
  consults prev (no snapshot decode). Update() routes through
  sk.UpdateGOS when gosEpsilon>0. Reset clears the per-window
  dirty/wake state (gosEpsilon/gosSites are per-series config, survive).
- precompute.go: applyGosMode is already generic (structural
  SetGosMode assert); extended subWindowShouldEmit and
  subWindowMarkEmitted with a SketchTypeDDSketch branch mirroring
  CountSketch (bypass Gate-1's divergence pre-check in GOS mode).
- asapedgeprocessor warm_sketch.go: the DDSketch factory now primes
  SetGosMode at series CREATION (like the plain CountSketch factory) so
  inserts before a new series' first flush are gated too; the generic
  opts.gosDeltaEpsilon/gosSites plumbing and subWindowEnabled() already
  cover DDSketch unchanged.
- asapedgeprocessor config_validate.go / config.go: gos_delta_epsilon
  is now accepted for family=ddsketch as well as non-heap countsketch,
  and rejected (with a clear message) on every other family.

Tests (all three tiers, mirroring CountSketch):
- sketchlib-go DDSketch (in the sibling sketchlib-go commit):
  disabled-passthrough, deterministic crossing+reset, first-touch-only
  B tracking, and telescoping reconstruction (exact bucket parity).
- asap-precompute-go/sketches ddsketch_gos_test.go: empty-drain-returns-
  nil, wake fires once per batch and clears on read, wrapper-level
  telescoping via ComputeDeltaAgainst+ApplyDelta (+ residual) matching a
  never-reset reference in count and quantiles.
- asapedgeprocessor gos_ddsketch_test.go: TestGOSDDSketchInsertWakesFlush
  — full pipeline, SubWindowInterval UNSET and WindowDuration=1h (neither
  can fire on its own), DDSketch observations through ConsumeMetrics
  alone produce a flushed envelope with no manual wakeSubWindow call.
  gos_ddsketch_validate_test.go: per-family accept/reject matrix.

go build / go vet / go test clean on sketchlib-go's DDSketch package,
asap-precompute-go (all subpackages), and asapedgeprocessor.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@zzylol
zzylol force-pushed the split/pr-gos-ddsketch branch from 3a18b97 to 250d7a8 Compare July 17, 2026 02:35
@zzylol
zzylol changed the base branch from split/pr-gos-countsketch to split/pr-gos-cms July 17, 2026 02:35
@zzylol
zzylol changed the base branch from split/pr-gos-cms to main July 17, 2026 15:46
@zzylol
zzylol merged commit 92ea05a into main Jul 17, 2026
@zzylol
zzylol deleted the split/pr-gos-ddsketch branch July 17, 2026 15:52
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