[Performance]: After /compact, 77–96% of the session .jsonl is unreachable but re-parsed in full — cost tracks file size, not live context
Summary
After /compact (or auto-compact), the session .jsonl keeps every pre-compaction record. They stay forever, but they are no longer reachable: the compact_boundary record has parentUuid: null, so the message chain is deliberately cut there.
The problem is not that they're kept — it's that readSDKSessionFile() re-reads and re-parses the whole file from byte zero, including all of them, and it does so synchronously on the renderer main thread. So parsing cost is proportional to file size, which only ever grows, and not to live context, which compaction just shrank.
Concretely: one of my sessions is at 85.7 MB / 14,904 records while its live chain is 573 records / 3.6 MB — 96% of the bytes are unreachable, and every hydration parses all of it.
The user-visible symptom is that a conversation gets steadily slower as it grows, and gets markedly worse after each compaction — which is counter-intuitive, because compaction is what reduced the context.
Environment
- Claudian 2.3.3 (plugin ID
realclaudian) — i.e. the current release, not an outdated build - Obsidian 1.13.7, Windows 11
- Claude provider via
ANTHROPIC_BASE_URL+ANTHROPIC_AUTH_TOKEN, custom non-claude-*model with a 1M context window (Deepseek-V4-Flash[1m]) - Claude Code 2.1.217 (
bin/claude.exe, npm global) - Settings:
maxWarmAgentProcesses: 5,restoreTabsOnStartup: true,maxTabs: 3,loadUserSettings: true autoCompactEnabledunset (inherited default); compaction observed istrigger: "auto"CLAUDE_CODE_AUTO_COMPACT_WINDOW: 1020000andCLAUDE_CODE_MAX_CONTEXT_TOKENSset in~/.claude/settings.json— i.e. I deliberately let conversations run to ~1M tokens before compacting. That's a legitimate configuration and it explains the scale below, but it also means each compaction strands nearly a million tokens of records at once.
Why this is compaction-specific
Before the first compaction, file size ≈ live context, so the parse cost is "fair" and reads as ordinary context-driven latency. After the first compaction the two diverge permanently:
file size live chain
before c1 14 MB 14 MB (≈ equal)
after c1 14 MB → grows 3 MB (diverging)
after c4 92 MB 3.6 MB (96% dead)Each compaction adds records and removes none. So the dead fraction grows monotonically with the number of compactions:
| Session | File | Records | Compactions | Live chain | Unreachable bytes |
|---|---|---|---|---|---|
4fa87314… |
85.7 MB | 14,904 | 4 | 573 rec / 3.6 MB (4.2%) | 82.1 MB (96%) |
9cfabb78… |
46.2 MB | 5,864 | 2 | 382 rec / 6.3 MB (13.5%) | 39.9 MB (86%) |
4e3074ff… |
68.2 MB | 8,335 | 3 | 1,286 rec / 15.6 MB (22.8%) | 52.6 MB (77%) |
Across all 9 of my sessions that contain a compact_boundary: 382.2 MB of transcript, of which 174.4 MB (45.6%) is unreachable.
A representative compactMetadata from one of them:
{ "trigger": "auto", "preTokens": 969612, "postTokens": 8675,
"cumulativeDroppedTokens": 960937, "durationMs": 43819,
"preservedSegment": { "headUuid": "…", "anchorUuid": "…", "tailUuid": "…" },
"preservedMessages": { "anchorUuid": "…", "uuids": [ … ], "allUuids": [ … ] } }Note postTokens: 8675 against an 85.7 MB file — a ~10,000:1 ratio of dead bytes to live context.
Source reference
src/providers/claude/history/sdkSessionPaths.ts — readSDKSessionFile() on main (2.3.3):
const content = await fs.readFile(sessionPath, 'utf-8');
const lines = content.split('\n').filter(line => line.trim());
for (const line of lines) {
try { messages.push(JSON.parse(line) as SDKNativeMessage); }
catch { skippedLines++; }
}There is no incremental read, no byte/line offset, no worker thread, and no cache of parsed messages — every call re-reads from byte zero. All of that work is synchronous on the renderer main thread.
I reproduced the loader's three steps in Node on the same files to size it:
| File | readFile |
split+filter |
JSON.parse × n |
Total (sync block) |
|---|---|---|---|---|
| 92.2 MB / 14,904 lines | 442 ms | 126 ms | 324 ms | 892 ms |
| 72.5 MB / 8,335 lines | 318 ms | 98 ms | 301 ms | 717 ms |
Noting that JSON.parse is only ~36% of it — so skipping the dead records' parse alone is not enough; the read + split has to become incremental too.
Reproduction (no new model requests needed)
On any session that has been compacted, walking parentUuid from the last childless record shows the chain stops at the boundary:
# boundary record shape
{ "type": "system", "subtype": "compact_boundary",
"parentUuid": null, # ← chain deliberately cut here
"logicalParentUuid": "1fa1bd62-…", # pre-compaction leaf
"compactMetadata": { … } }
# every record after it points at the boundary's uuidSo "reachable" is computable from the file alone, and the ratio above is directly measurable.
Relationship to existing issues
I checked these before filing, and I don't believe this is a duplicate:
- #1306 (
/compactstalls inside Claudian vs 34 s in the CLI) — different symptom. It's about compaction not completing and its outcome not being surfaced. Its body mentions the synchronousreadSDKSessionFileonly in passing, and attributes that to #1303 — but #1303 turned out to be about DOM deferral, not the file parse. So the parse itself was never filed on its own. - #1303 → PR #1304 (merged) — defers creating collapsed tool/diff DOM subtrees. Different layer entirely; doesn't touch the transcript read.
- #1212 (closed) — composer autosize causing synchronous reflow per keystroke → typing lag in long conversations. Different cause.
- #931 (open PR,
getSDKSessionSignature()=size:mtimeMs) — this detects externally appended turns and then re-hydrates the whole transcript. It explicitly does not read only the new bytes. So it makes the full-parse path fire more often, which is exactly the case for fixing the reader itself. - #598 (closed by inactivity bot) — auto-compaction never enabled. Different.
Suggested direction
Two independent wins, either of which stands alone:
Skip unreachable records cheaply. The file is append-only,
compact_boundary.parentUuid === nullcuts the chain, andcompactMetadata.preservedMessages.allUuidsdeclares what must be kept. A reader that first locates the last boundary on the chain can decide reachability without parsing the records before it. (A cheap pre-filter on the raw line — e.g. a substring test for"parentUuid"/ the boundary marker — lets you avoidJSON.parseon lines you're going to drop anyway.)Read incrementally. The transcript is append-only, so a
lastReadSizeper session plus reading from that offset would make the common case read ~0 bytes. This is the fix that generalizes beyond compaction, and it composes with #931: the signature check already exists as the change detector — it just needs to feed a tail read instead of a full re-hydration.
Off main thread (worker) would help too, but 1+2 reduce the work rather than relocating it.
What I could and couldn't measure — and a possible workaround to sanity-check
I can measure the reader's cost directly (above) because it's plain Node work. What I cannot measure from inside the plugin is how much of the per-turn latency is this reader versus the CLI re-reading the same file. Hydration is guarded by hydratedConversationIds, so I believe the full parse happens once per conversation per plugin runtime (plus on every conversation switch), not once per turn — so I'd expect this to show up as a multi-second freeze on open/switch rather than per-turn lag. I'd rather flag that uncertainty than overclaim.
Separately, I worked around it by pruning the unreachable records out of the .jsonl files directly (keeping the last boundary + preservedMessages.allUuids + their parentUuid closure + an iterative closure over any uuid referenced by a kept record). On a copy, the live chain's uuid sequence is bit-identical before and after, all records still parse, and there are no dangling references:
| Session | Before | After | Saved |
|---|---|---|---|
4fa87314… |
92.2 MB | 21.1 MB | −77.1% |
9cfabb78… |
49.3 MB | 27.9 MB | −43.3% |
That's a workaround, not a fix — it costs the ability to rewind past the cut, and it only helps because the reader is file-size-proportional. Mentioning it as evidence that the dead weight is genuinely removable without disturbing the active chain.
Happy to help test an incremental reader, or to provide more of my session files if the numbers would be useful.
Source: YishenTu/claudian