Repository navigation
Inbox: hold only the watched threads' decisions (memory soak growth doubled by #4016) - #4139
Merged
Merged
Conversation
Decision mode turned on by default (#4016), so every window read GET /api/inbox/decisions, which lists every open decision in the store, and kept the whole list in state. On the memory soak's store that is 2,610 decisions, 4.25 MB of JSON: the heap at open rose 4.7 MB and the soak's growth went from 4 to 13 MB, for people who never open decision mode. The window draws decisions only for the threads it watches (a pane's "Decide these N", the sitting's thread). A read now keeps those threads' decisions and a count for every thread, so a thread just opened still shows its count at once.
A thread just opened shows its "Decide these N" from the read's counts, before its decisions are held. Pressed in that moment, the sitting got an empty queue and flashed its end screen until the read landed; it now shows its loading state until a read has kept that thread's decisions.
A thread just opened shows its "Decide these N" from the read's counts, before its decisions are held. A sitting opened then now: - takes its thread's name from its first decision once the read lands; - reads again up to three times, and draws again after each read that landed, so a thread with nothing left ends the sitting instead of leaving it on "Reading what waits on you…"; - after three failed reads, says so with the card's existing "Couldn't read the question. Try again". The read itself moves out of App.tsx (decisions/keptRead.ts) and returns whether it landed. App.tsx shrinks by six lines (ceiling 6294 -> 6288).
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.
The memory soak (
tests/e2e/inbox-memory-soak.spec.ts) has failed now and then since 25 Nov and was rerun as a flake. It is not a flake. One merge doubled its growth.Evidence (main's soak, read from CI logs from 6 Nov on). Growth was 3.4 to 7.0 MB from 6 Nov until 1c60ce1 (25 Nov 18:22: 4.1 MB, open heap 107.3 MB). The next run, on 9d77678 (the merge of #4016), read 13.1 MB, with the open heap at 112.0 MB. All 11 runs since read 8.6 to 13.5 MB, with the open heap at 110.1 to 112.0 MB. The only other commit in between is #4053 (CSS and an HTML frame). Listeners and DOM nodes are the same before and after: the growth is JS data. The roughly 50 listeners per round were already there on 16 Nov. They belong to the open thread's new message, which is on screen.
Cause. #4016 turned decision mode on by default (
useDecideSitting.ts,settings.decision_mode.on). Each window then readGET /api/inbox/decisionsand kept the whole answer inApp.tsxstate. That answer is every open decision in the store. On the soak's own seed (scripts/inbox-large-store.ts, measured in process) it is 2,610 decisions over 1,722 threads, or 4.25 MB of JSON. Every window paid for it, whether or not anyone opened decision mode. The read happens again for each message into the open thread. The soak's new step of about 6 MB between samples 150 and 180 falls on message 151, the first question in the open thread, when a changed list was read and swapped in.Fix. The window draws decisions only for the threads in its existing
watchedset: a pane's "Decide these N" and the sitting's thread. A read now keeps those threads' decisions (keepWatchedindecisions/model.ts) and a count for every thread. A thread just opened therefore still shows its count at once. The filter runs beforesetDecisions, so no state updater captures the full read. Nothing on screen changes.App.tsxis one line shorter (ceiling 6295 → 6294).Not in this PR: the server still builds the whole list, and the window still parses it, on each read that touches a watched thread. That memory is freed after the read, but it costs CPU. A
?threads=filter on the route would remove it.Tests:
packages/inbox/decisionsModel.test.ts17/17 (1 new),tests/inbox-structure.test.ts5/5,tsc -p packages/inboxclean. The proof is the soak shard in this PR's e2e run.Round 2 (review). A thread just opened shows its "Decide these N" from the counts, before its own decisions are held. A sitting opened in that gap now:
The read moved to
decisions/keptRead.ts(App.tsx6294 → 6288 lines, ceiling lowered). The event stream's reconnect does not read the decisions again; its catch-up after a silence does.Known and left: past 64 watched threads the set starts over. A tucked sitting can then show its loading state for one read until its thread joins again.
New DOM test
packages/inbox/decisionSittingWait.test.tsxcovers the three outcomes. I checked that each case fails without its fix.