perf(tiles): no snapshot of the session the grid parks when it becomes a tile

Opening the grid runs _cleanupPreviousSession() once to park the main
terminal, and for a non-shell session that serialized the terminal
(1000 lines of scrollback) into the snapshot cache and up to 256 KB of
localStorage. Closing the grid drops the main terminal's snapshot of
every tiled id (stale by then), so when the parked session is itself a
tile, which it is unless the grid opens on a set without it, that copy
was always thrown away. openTileGrid now passes skipSnapshot in exactly
that case; a parked session that stays out of the grid (Open group as
tiles from another session) keeps its snapshot as before.

Measured: the same serialize on the main terminal's buffer costs 32 to
42 ms per grid open (n=6, 35 KB) plus the localStorage write; shells
never took one, so the A/B runs (shells) show no difference. Snapshot
serializes per grid open with a non-shell session active and tiled:
1 -> 0.

Tests: the grid passes skipSnapshot only when the parked session is
tiled; the real _cleanupPreviousSession skips the serialize only when
asked; mutation-checked both ways.

Scope: PR 2 (tile-grid.js, the app.js seam).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer
2026-10-07 08:57:42 +02:00
parent 7990249e2d
commit ec5e4aa3e1
3 changed files with 38 additions and 2 deletions
+4 -1
View File
@@ -7587,7 +7587,9 @@ class CodemanApp {
}
}
_cleanupPreviousSession(newSessionId) {
// `skipSnapshot`: the tile grid opening on the session it parks
// (tile-grid.js openTileGrid), whose snapshot closing the grid discards.
_cleanupPreviousSession(newSessionId, { skipSnapshot = false } = {}) {
// Snapshot the OUTGOING session's xterm rendered state (viewport + scrollback +
// colors/attrs) before the terminal gets cleared/reset. Lets us restore the
// exact view on switch-back rather than replaying codex's byte stream, which
@@ -7598,6 +7600,7 @@ class CodemanApp {
// quota for them. Unknown/undefined mode still snapshots, matching restore.
const outgoingSession = this.activeSessionId ? this.sessions?.get?.(this.activeSessionId) : null;
if (
!skipSnapshot &&
this.activeSessionId &&
outgoingSession?.mode !== 'shell' &&
this._serializeAddon &&
+5 -1
View File
@@ -202,7 +202,11 @@ Object.assign(CodemanApp.prototype, {
return true;
}
this._cleanupPreviousSession(focus);
// No snapshot of a session that becomes a tile: closing the grid drops the
// main terminal's snapshot of every tiled id (stale by then), so taking one
// here (a 1000-line serialize and up to 256 KB of localStorage for a
// non-shell session) only ever produced a copy that was thrown away.
this._cleanupPreviousSession(focus, { skipSnapshot: wanted.includes(this.activeSessionId) });
grid.open = true;
grid.ids = [];
grid.focusedId = focus;