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 crossed the gRPC boundary, fired its own renderer event, and wrote its own dev_log entry. For a workspace with the Git extension actively probing on file changes, this 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 renderer emit + a single dev_log line. The downstream Output panel still sees identical text - just delivered in larger chunks.

Β§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.
  • The flusher 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 the renderer. 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.