Skip to content

tooling: in-app memory snapshot command to attribute RAM growth #566

@Axelj00

Description

@Axelj00

Problem

Users report ClawTerm "eating insane amounts of RAM" and we have no way to confirm where it's going without asking them to attach a Chrome devtools heap snapshot. That's a tall order — the user has to know about `tauri::WindowExt`, open devtools in a webview that doesn't expose it by default, take the snapshot, and ship a multi-MB file.

Meanwhile our internal mental model of "where the RAM goes" is fragmented across:

A user reporting "ClawTerm is using 3 GB" gives us no idea which of the above is the culprit. We're flying blind.

Proposal

Add a `Memory Diagnostics` command in the palette that produces a structured report:

```
ClawTerm Memory Snapshot — 2026-05-23 22:00:00

Tabs: 4 Panes: 8 WebGL contexts: 6/6

Per-pane (8 panes):
pane-1 scrollback=5000 image=42MB pending=0KB
pane-2 scrollback=5000 image=128MB pending=0KB ← image cap hit
pane-3 scrollback=1000 image=8MB pending=0KB (hidden, compacted)
...

Aggregated:
Scrollback total ~35 MB (estimated, 480 B/line × cols)
Image storage total ~340 MB ← largest contributor
Event history total ~1 MB
Tray records 50 entries (~25 KB)
Closed-tab stack 10 entries (~5 KB)

JS heap (performance.measureUserAgentSpecificMemory):
Total: 480 MB (Web platform measurement, Chromium only)

Process RSS (from get_self_rss IPC):
680 MB ← what Activity Monitor shows
```

Easy to copy-paste into a bug report. Easy for us to read and immediately know "image storage is 340 MB → check #565 / lower the cap."

Implementation sketch

  1. `ImageAddon.storageUsage` (MB) is already exposed by the addon — call per-pane.
  2. `Terminal.buffer.active.length` for scrollback line count.
  3. `pendingBytes` is already tracked per pane.
  4. `performance.measureUserAgentSpecificMemory()` for JS heap — requires the page to be cross-origin-isolated; verify Tauri webview qualifies.
  5. New Rust command `get_self_rss` calling `proc_pidinfo(getpid(), PROC_PIDTASKINFO)` — we already have the syscall wrapper from Show per-pane memory usage (RSS) in the footer #560.
  6. Command palette: "Memory Diagnostics" → modal showing the report + a "Copy to Clipboard" button.

Why this is worth building

Two reasons:

  1. Self-diagnosis. The user can answer "is it the images or the scrollback?" themselves without filing an issue.
  2. Triage. When users do file RAM complaints, we can ask them to run this command and paste the output. Better than a flame-graph upload.

Reuses the modal pattern from #553 / #554 — small surface, large clarity gain.

Out of scope

  • Continuous monitoring / leak detection. One-shot snapshot is enough.
  • GC-trigger button — Chromium will GC under pressure; we don't need a button.
  • Per-pane breakdown of WebGL GPU memory — not exposed by the WebGL spec.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance improvementspriority: mediumImportant but not urgenttech-debtTechnical debt and code quality

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions