Repository navigation
perf(store): throttle envelope writes, cap parsed transcripts (#1475) - #1481
Merged
currentbits merged 4 commits intoOct 5, 2026
Merged
Conversation
Every debounced flush rewrote the whole ~6 MB envelope, even when a stream had only appended to its message shard. Track envelope dirtiness apart from the shard dirty sets: a 250 ms flush now writes only the dirty shards, and the envelope rides along at most once per ENVELOPE_THROTTLE_MS (2 s). Shard deletes still commit together with the envelope. saveNow(), the exit hook and every quit path still write the envelope immediately and do not start a throttle window. Atomic tmp + fsync + rename and the .bak are unchanged. Trade-off: a crash (not a quit) can lose up to 2 s of envelope-only changes (thread rows, usage, settings); transcripts and work logs are unaffected. scripts/perf/store-stream-bench.js, one 30 s stream on a /tmp copy of the real 5.8 MiB store: main: 99 envelope writes, 571.78 MiB (19.02 MiB/s), stringify 3920 ms branch: 14 envelope writes, 80.86 MiB ( 2.70 MiB/s), stringify 459 ms Co-Authored-By: Claude Opus 5.5 <[email protected]>
_messagesHydrated kept every opened thread's parsed transcript for the session (+3-5 MB heap per large thread, never released). Track read order and, past MAX_HYDRATED_THREADS (8), drop the least recently read thread back to its shard; the next read re-parses it. A thread is only evicted when its shard on disk is current: never while working, dirty, mid-flush, deleted or still on the legacy inline blob. Real-data load of a /tmp copy (2,103 threads, all 315,379 messages read): same sha256 of envelope + work logs + transcripts as main, with 8 threads left hydrated instead of 2,103. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Appends inside the window write the shard only; envelope changes coalesce; saveNow and the exit hook still write at once; a crash loses at most the window; shard deletes commit with the envelope; the cache keeps running and dirty threads and rehydrates evicted ones. All but the delete guard fail against main's store.js. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replays PM1's stream shape (40 deltas/s, assistant message every 1.8 s, tool call every 2 s, 30 s) through the runner's Store calls on a clone of a /tmp copy of the real store; refuses paths outside /tmp. main: 99 envelope writes, 571.78 MiB (19.02 MiB/s), stringify 3920 ms branch: 14 envelope writes, 80.86 MiB ( 2.70 MiB/s), stringify 459 ms Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This was referenced Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1475, main-process finding 1 (rewriting the envelope while streaming took 92% of main-process JS time).
What changed
coder-store.jsonis written at most once every 2 s from the debouncedsave()path. Transcript and work-log files keep the 250 ms debounce.saveNow()(quit, shutdown, tests) isn't throttled. A flush that deletes a transcript file always writes the envelope in the same commit, so a crash can't leave a thread row whose transcript is already gone.appendMessage,updateMessageandsetMessagesall slice), so no caller holds an array it later edits in place.Verified independently
Benchmark (
scripts/perf/store-stream-bench.js), run on a clone of the real store (5.8 MiB envelope), 20 s simulated stream:Randomized stress test: 3,000 ops across 30 threads (append, update, read), with eviction active. No mismatches against the in-memory model, live or after reload. Browsing 30 threads peaks at 10 transcripts in memory; main keeps all 30.
Electron suite: 4132 of 4132 passing.
New tests:
store-flush-throttle.test.jsfails on main (7 failures).Trade-offs
🤖 Generated with Claude Code