Expand description
Adaptive resize stream coalescer.
This module implements the resize coalescing behavior specified in
docs/spec/resize-scheduler.md. It provides:
- Latest-wins semantics: Only the final size in a burst is rendered
- Bounded latency: Hard deadline guarantees render within max wait
- Regime awareness: Adapts behavior between steady and burst modes
- Decision logging: JSONL-compatible evidence for each decision
§Usage
ⓘ
use ftui_runtime::resize_coalescer::{ResizeCoalescer, CoalescerConfig};
let config = CoalescerConfig::default();
let mut coalescer = ResizeCoalescer::new(config, (80, 24));
// On resize event
let action = coalescer.handle_resize(100, 40);
// On tick (called each frame)
let action = coalescer.tick();§Regime Detection
The coalescer uses a simplified regime model with two states:
- Steady: Single resize or slow sequence — prioritize responsiveness
- Burst: Rapid resize events — prioritize coalescing to reduce work
Regime transitions are detected via event rate tracking with hysteresis.
§Invariants
- Latest-wins: the final resize in a burst is never dropped.
- Bounded latency: pending resizes apply within
hard_deadline_ms. - Deterministic: identical event sequences yield identical decisions.
§Failure Modes
| Condition | Behavior | Rationale |
|---|---|---|
hard_deadline_ms = 0 | Apply immediately | Avoids zero-latency stall |
rate_window_size < 2 | event_rate = 0 | No divide-by-zero in rate |
| No pending size | Return None | Avoids spurious applies |
§Decision Rule (Explainable)
- If
time_since_render ≥ hard_deadline_ms, apply (forced). - If
dt ≥ delay_ms, apply when in Steady (or when BOCPD is enabled). (delay_ms= steady/burst delay, or BOCPD posterior-interpolated delay when enabled.) - If
event_rate ≥ burst_enter_rate, switch to Burst. - If in Burst and
event_rate < burst_exit_rateforcooldown_frames, switch to Steady. - Otherwise, coalesce and optionally show a placeholder.
Structs§
- Coalescer
Config - Configuration for the resize coalescer.
- Coalescer
Stats - Statistics about the coalescer state.
- Cycle
Time Percentiles - Cycle time percentiles for reflow diagnostics (bd-1rz0.7).
- Decision
Evidence - Evidence supporting a scheduler decision with Bayes factors.
- Decision
Log - Decision log entry for observability.
- Decision
Summary - Summary of decision logs.
- Regime
Change Event - Event emitted when regime changes between Steady and Burst (bd-bksf.6 stub).
- Resize
Applied Event - Event emitted when a resize operation is applied (bd-bksf.6 stub).
- Resize
Coalescer - Adaptive resize stream coalescer.
- Telemetry
Hooks - Telemetry hooks for observing resize coalescer events.
Enums§
- Coalesce
Action - Action returned by the coalescer.
- Regime
- Detected regime for resize events.
Type Aliases§
- OnCoalesce
Decision - Callback type for coalesce decision events.
- OnRegime
Change - Callback type for regime change events.
- OnResize
Applied - Callback type for resize applied events.