Implication: allocation stress clusters around long sessions near context-window limits, not normal short sessions.
Estimated Smith persistent storage
Smith stores length-prefixed CBOR, not JSONL. Rough storage estimate:
JSON key overhead disappears/reduces strongly in CBOR,
text/tool output bytes remain dominant,
expected CBOR session size ≈ 60–85% of Pi JSONL size for text-heavy entries,
corpus would likely be ≈ 237–336 MiB as CBOR instead of 395 MiB JSONL.
Worst observed Pi session as Smith CBOR:
file: ≈ 18–25 MiB,
in-memory loaded session: ≈ 30–45 MiB depending on String capacity, Vec overhead, indexes, and cached render state.
Typical Smith loaded session:
p50: < 1 MiB resident,
p75: 1–2 MiB resident,
p95: 4–8 MiB resident,
p99: 12–20 MiB resident.
Loading every session fully would be wasteful: estimated resident memory ≈ 0.7–1.2 GiB. Smith should index metadata lazily and load only active/replayed sessions.
Allocation hot spots by subsystem
Session load/replay
Expected allocations:
one Vec<SessionEntry> growth per loaded session,
one String allocation per content block / id / metadata text,
Dominant bytes: tool results and assistant/thinking text, not entry structs.
Candidate optimization:
pre-size entries from frame count where possible,
intern repeated provider/model/tool names only if measured,
lazy decode large content blocks for history browsing if necessary,
keep session discovery metadata separate from full session load.
Arena fit: poor for persisted entries. Sessions need stable IDs, replay, unknown-entry preservation, and long lifetimes.
Provider request construction
Expected allocations:
select context entries,
clone/transform message text and tool schemas into provider request shape,
secret proxy scan/replace may allocate rewritten strings,
JSON tool args/definitions allocate maps/strings.
Dominant bytes: selected context window, often 100k–300k tokens near compaction.
Arena fit: possible for temporary request assembly only if provider API can borrow from scratch lifetime. Async stream boundary likely forces owned request data. Measure before adding arenas.
TUI render / virtual scroll
Expected allocations:
visible-window message formatting,
markdown parse/render intermediates,
syntax highlight spans,
diff view lines/spans,
wrapped text buffers,
tool result collapsed/expanded summaries.
Dominant cadence: 16ms render tick. Reallocating formatted strings/spans every tick is riskier than session storage size.
Arena fit: best candidate, but only for per-frame scratch buffers and only if widgets do not retain references after frame.
Agent event streaming
Expected allocations:
many small text/thinking deltas,
growing assistant message buffer,
tool-call argument accumulation,
event fanout to session/TUI/hooks.
Optimization candidates:
accumulate deltas in one String with capacity growth,
avoid creating one session entry per tiny delta,
TUI incremental append instead of full rerender parse where possible.
Arena fit: weak. Streaming state crosses awaits and event consumers.
idle TUI + current normal session: tens of MiB RSS mostly from terminal/UI/libs/Lua, not session entries,
active long session: +10–50 MiB for session + render/request buffers,
provider request at compaction threshold: temporary spike proportional to selected context, likely +20–100 MiB depending provider serialization,
pathological large tool output/render: single-line or single-message allocation can reach MiB scale.
Memory policy candidates:
Lazy-load full sessions; discovery reads only metadata.
Never store session history in arenas.
Benchmark render/request scratch before adding bumpalo.
Put hard output-size and render-size tests in prototypes.
Virtual scroll must bound per-frame work by visible rows, not total entries.
Compaction/request construction needs peak-memory measurement, not only CPU timing.
Arena / allocator decision estimate
Arenas likely help only where allocation lifetime is phase-bounded. They do not
solve dominant persisted text bytes.
Arena value is broader than allocation-count reduction:
fewer global allocator calls → lower allocator/syscall pressure,
stable peak/live memory after repeated phases,
predictable reset cadence,
bounded scratch capacity growth,
easier bulk discard of temporary render/request objects.
Recommended prototype gates:
baseline must measure allocation count, allocated bytes, peak live bytes,
post-warmup live-memory plateau, elapsed time, and allocator-call pressure;
use /proc/self/statm RSS sampling on Linux for stable-memory checks;
bumpalo variant only for render/request scratch;
keep/drop decision can pass by allocation reduction OR lower allocator-call
pressure OR materially flatter post-warmup memory profile, without lifetime/API
complexity.
Plugin heap limiting is a separate allocator/control use case. mlua::Lua
exposes used_memory() and set_memory_limit(limit_bytes), which should be
prototyped against Smith's locked mlua + LuaJIT feature set. This is not
bumpalo; it is Lua VM heap quota enforcement.
Plugin reload is the broader arena/domain use case. A per-plugin domain can own
Lua state plus host-side plugin allocations/caches/subscriptions. Dropping the
domain on reload gives predictable reclamation and avoids bespoke cleanup graphs,
provided no callback/task/registry handle can escape its domain.