Skip to content

mecatui: stop the per-turn memory growth in blockRenderCache #2409

Open

Description

@peppescg

Problem

mecatui's RSS grows ~200 KB per turn and never comes back: 106 → 296 MiB over a 1,000-turn session (scripted, mock LLM, mecatui connect).

A heap profile at 0 / 100 / 300 turns attributes the growth to blockRenderCache (cmd/mecatui/ui/block_cache.go), which keeps an entry for every block in the conversation:

  • rendered[i]: the full rendered block plus provenance;
  • markdown[i]: the raw glamour output of the same block (~47 KB per assistant answer in the scenario). It's only needed to re-render a block, and a settled block re-renders only on width or expand changes;
  • prefixLines / prefixProvenance: the assembled settled frame, one more copy of every line.

Nothing is ever evicted except on a conversation rebuild.

Proposal

  1. Drop markdown[i] once a block has settled. f9 or a resize re-runs glamour for that block. This roughly halves the growth (−47 KB/turn) and needs no other change.
  2. With a virtualized transcript (perf(mecatui): profile long-transcript viewport replacement #1273), bound rendered to the blocks around the viewport (plus overscan), so settled blocks far from it are re-rendered on scroll-back. In the prototype, the heap stays flat at ~16 MiB, and RSS stays flat from 200 to 1,000 turns.

Acceptance

  • A long-session benchmark (≥ 500 turns) shows memory flat after warm-up.
  • f9 expand/collapse, resize, selection, and scroll-back render the same output as today (goldens).

Activity

  1. self-assigned this
    on Oct 18, 2026
  2. added
    tui
    on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

tui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions