Skip to main content

Module resize_coalescer

Module resize_coalescer 

Source
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

ConditionBehaviorRationale
hard_deadline_ms = 0Apply immediatelyAvoids zero-latency stall
rate_window_size < 2event_rate = 0No divide-by-zero in rate
No pending sizeReturn NoneAvoids spurious applies

§Decision Rule (Explainable)

  1. If time_since_render ≥ hard_deadline_ms, apply (forced).
  2. 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.)
  3. If event_rate ≥ burst_enter_rate, switch to Burst.
  4. If in Burst and event_rate < burst_exit_rate for cooldown_frames, switch to Steady.
  5. Otherwise, coalesce and optionally show a placeholder.

Structs§

CoalescerConfig
Configuration for the resize coalescer.
CoalescerStats
Statistics about the coalescer state.
CycleTimePercentiles
Cycle time percentiles for reflow diagnostics (bd-1rz0.7).
DecisionEvidence
Evidence supporting a scheduler decision with Bayes factors.
DecisionLog
Decision log entry for observability.
DecisionSummary
Summary of decision logs.
RegimeChangeEvent
Event emitted when regime changes between Steady and Burst (bd-bksf.6 stub).
ResizeAppliedEvent
Event emitted when a resize operation is applied (bd-bksf.6 stub).
ResizeCoalescer
Adaptive resize stream coalescer.
TelemetryHooks
Telemetry hooks for observing resize coalescer events.

Enums§

CoalesceAction
Action returned by the coalescer.
Regime
Detected regime for resize events.

Type Aliases§

OnCoalesceDecision
Callback type for coalesce decision events.
OnRegimeChange
Callback type for regime change events.
OnResizeApplied
Callback type for resize applied events.