Skip to content

perf(store): cap hydrated transcripts by bytes as well as count (#1475) - #1488

Merged
currentbits merged 1 commit into
mainfrom
coder/perf-h-mainheap-byte-budget-transcript-c-c31b39
Oct 6, 2026
Merged

currentbits merged 1 commit into
mainfrom
coder/perf-h-mainheap-byte-budget-transcript-c-c31b39

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Part of #1475, round 3, from PM3's 'didn't move' list: the hydrated-transcript LRU from #1481 capped by count only.

What changed

  • Adds MAX_HYDRATED_BYTES (16 MiB of shard JSON) next to the 8-thread count cap.
  • The most recent read is never evicted, so one huge thread isn't re-parsed on every read.
  • Eligibility rules are unchanged: working, dirty, in-flight and legacy-blob threads are never evicted, so the cap stays soft.

Measured (worker, clone of the real store, forced GC, 3 runs): opening the 10 largest threads adds +19.2 MB of heap instead of +32.8 MB (−41%). Store load is unchanged (55 vs 56 ms).

Verified independently

  • The new store-hydrated-budget.test.js fails on main: 3 of 4 tests.
  • My earlier randomized stress tests pass with 0 mismatches, live and after reload.
  • typecheck exits 0; test:electron 4156 of 4156.

Not done, deliberately: lazy side-file reads at boot. Measured at ~19 ms of an ~85 ms Store load.

  • Notes ride on every thread record, and the restored thread needs them ~200 ms later anyway.
  • Usage is 5.5 ms, under the 15 ms bar, and a lazy read that failed could let a save overwrite the file empty.

🤖 Generated with Claude Code

Opening the 10 largest real threads held 8 parsed transcripts (~32.8 MB
of heap). A 16 MiB shard-size budget on the same LRU keeps 5 of them
(+19.2 MB, -41%). Sizes come from the parsed JSON and refresh on flush;
the most recent read is never evicted so one huge thread isn't re-parsed
per read. Eligibility rules (working, dirty, in-flight, legacy) unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T09:53:12.513774Z 5255a69 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5255a693ff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread electron/store.js
if (Object.prototype.hasOwnProperty.call(this._messagesHydrated, id)) {
json = JSON.stringify(this._messagesHydrated[id] || []);
// Refresh the LRU size estimate in place (Map.set keeps the order).
if (this._hydratedReads.has(id)) this._hydratedReads.set(id, json.length);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Evict newly clean transcripts after flushing

When several hydrated transcripts are created or enlarged through setMessages, they are correctly pinned while dirty, and this line updates their size estimates during the flush. However, neither the synchronous nor asynchronous flush invokes _evictHydrated after the writes become clean; eviction only runs on a later cache miss in _hydrateMessages. If subsequent accesses are all cache hits, the hydrated cache can therefore remain arbitrarily above the new 16 MiB budget indefinitely, defeating the cap for actively created or grown threads.

Useful? React with 👍 / 👎.

@currentbits
currentbits merged commit 644df8e into main Oct 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant