Skip to main content

Module OutputChannelCoalesce

Module OutputChannelCoalesce 

Source
Expand description

Per-channel coalescing buffer for outputChannel.append notifications.

Cocoon’s Git extension emits 30+ append notifications per git status (one per [trace] [OperationManager][...] line, one per executed sub-command). Each one previously:

  1. Crossed the Cocoon → Mountain gRPC notification boundary.
  2. Fired its own Tauri::Emitter::emit("sky://output/append") round-trip.
  3. Wrote its own dev_log entry.

For a workspace with the Git extension actively probing repo state on file changes, the volume of [OperationManager] traces alone accounted for ~1.9k lines of one 28k-line session log.

This atom buffers appends per-channel for a short window (COALESCE_WINDOW) and flushes the concatenated payload as a single Sky emit + a single dev_log line. The downstream Output panel still sees identical text - just delivered in larger chunks - which matches the user-perceived UX of an output channel (it scrolls in chunks, not character-by-character).

§Why this is safe

  • Per-channel buffer means ordering is preserved within a channel.
  • Append-only semantics mean partial-payload visibility cannot expose torn writes - the buffered text is always a prefix of the eventual full payload.
  • Tauri::Emitter serialises emits per channel; the flush task running on the tokio runtime keeps the same back-pressure shape the per-call path had.

§Disable hook

OutputCoalesce=0 reverts to per-append emit (debugging synchronisation issues where a single append must be flushed immediately to disk).

Structs§

CoalesceChannel 🔒
PendingAppend 🔒

Constants§

COALESCE_WINDOW 🔒
Maximum delay between an append arriving and its flush to Sky. Tuned against the FSEvents / Git-extension 16ms tick - one frame is enough for a git status burst to fully accumulate without introducing a human-perceptible scroll lag.
MAX_BUFFERED_BYTES 🔒
Maximum buffered bytes per channel before a forced flush. Caps memory for any channel emitting unbounded text (a build extension piping cargo build stdout) before the timer fires.

Statics§

COALESCE_CHANNEL 🔒

Functions§

FlushOne 🔒
GetOrInitChannel 🔒
IsDisabled 🔒
TryEnqueue
Submit a pending append for coalescing. Returns true when the item was enqueued (the coalescer will flush within COALESCE_WINDOW), false when coalescing is disabled and the caller must flush inline.