Skip to main content

Module alloc_budget

Module alloc_budget 

Source
Expand description

Allocation budget: sequential leak detection using CUSUM + e-process.

Tracks allocation counts (or bytes) per frame as a time series and detects sustained drift (allocation leaks or regressions) with formal, anytime-valid guarantees.

§Detectors

  1. CUSUM — Cumulative Sum control chart for fast mean-shift detection. Sensitive to small, sustained drifts. Signals when the cumulative deviation from the reference mean exceeds a threshold.

  2. E-process — Anytime-valid sequential test (test martingale). Provides a p-value-like guarantee that holds under optional stopping: P(E_t ever exceeds 1/α | H₀) ≤ α (Ville’s inequality).

§Usage

use ftui_render::alloc_budget::{AllocLeakDetector, LeakDetectorConfig};

let config = LeakDetectorConfig::default();
let mut detector = AllocLeakDetector::new(config);

// Feed allocation counts per frame.
for count in [100, 102, 98, 105, 101] {
    let alert = detector.observe(count as f64);
    assert!(!alert.triggered);
}

§Evidence Ledger

Every observation produces an EvidenceEntry recording the residual, CUSUM state, and e-process value. This ledger is inspectable for diagnostics and can be serialised to JSONL.

§Failure Modes

  • False positive: bounded by α (default 0.05). Under H₀ (no leak), the e-process triggers with probability ≤ α across all stopping times.
  • Detection delay: CUSUM detects a shift of δ within approximately h / δ frames (where h is the threshold). E-process provides complementary evidence with stronger guarantees.

Structs§

AllocLeakDetector
Sequential allocation leak detector combining CUSUM and e-process.
EvidenceEntry
A single observation’s evidence record.
LeakAlert
Result of a single observation.
LeakDetectorConfig
Configuration for the allocation leak detector.