Skip to content

Boot: ~600 ms synchronous JSON.parse of the 183 MB store blocks the main process before first paint #639

Closed

Description

@currentbits

Measured on the live machine (2026-08-21, nightly): replaying the store load in node against the real coder-store.json (183 MB) costs 19 ms read + 581 ms JSON.parse — all synchronous on the main process. Store constructs with this.data = this._load() (electron/store.js:1019) → _readFile does readFileSync + JSON.parse (store.js:1032-1033) before any IPC handler can answer.

#618 reorders createWindow vs the boot chain, but even with the window up, the renderer's first real data (threads:list) still waits on this parse. And the cost grows with the store: +18-20 MB/week (~10%/week) on this machine.

Composition, for sizing the fix: 162 MB of the 181 MB of messagesByThread is the tool field (~70k tool-call records, each already truncated to 2 KB input / 4 KB output at write). Message text is only 9 MB total. So the parse cost is almost entirely transcript volume the sidebar never reads.

Fix direction (independent of, and much smaller than, #225 sharding):

  • Parse the envelope (threads, projects, settings, …) at boot; lazy-hydrate each thread's message array on first threads:get for that thread. The sidebar and Agents tab need only the envelope.
  • Or move the parse to a worker thread and unblock the IPC loop.

Acceptance: time-to-first-interactive-paint no longer scales with total transcript volume; boot parse of the threads-only envelope stays under ~50 ms at current size.

Activity

  1. added
    plan:todo
    plan:doing
    and removed
    plan:todo
    on Aug 21, 2026
  2. currentbits commented on Aug 21, 2026

    @currentbits
    OwnerAuthor

    Implemented on this branch: boot now JSON.parse's the envelope (~1.6 MB, 5–17 ms on the live 193 MB store) instead of the whole blob (332 ms JSON.parse).

    • electron/jsonEnvelope.js cuts messagesByThread out by walking the prefix until that key, then lastIndexOf of sibling keys (workLogByThread, settings, …). It does not skip-scan 191 MB of transcripts.
    • Each thread's array is JSON.parse'd on first getMessages / threads:get. getLastAssistantMessage peeks the raw array so threads:summaries does not hydrate tool payloads.
    • A hydrate-only session reuses the original messages JSON on save. First mutating save indexes the raw slice so unhydrated threads splice back in.
    • New saves emit messagesByThread last so the next boot takes the last-key path.

    Independent of #225 (per-thread files still wanted for flush CPU/disk). Acceptance: envelope parse no longer scales with transcript volume; measured well under 50 ms at current size.

  3. currentbits commented on Aug 21, 2026

    @currentbits
    OwnerAuthor

    Follow-up on this branch (coder/fork-fork-boot-600-ms-synchronous-json-p-ce848d): Agents-tab threads:summaries no longer peeks/hydrates messagesByThread.

    • Persist lastAssistantPreview: { text, at } | null on the thread row at setMessages / appendMessage.
    • Load-migrate rows that lack the field by peeking (not hydrating); persist so later boots stay envelope-only.
    • threadSummaries reads only that envelope field.

    Tests: summaries after reload without getMessages; appendMessage updates the preview; blank assistant falls through.

    Live store (read-only, 2026-08-21): 194 MB, 624 threads, envelope parse ~14 ms. First upgrade still skip-scans once (~270 ms) to fill the field; after persist, boot does not.

  4. currentbits commented on Aug 21, 2026

    @currentbits
    OwnerAuthor

    Follow-up #644 defers the first-upgrade lastAssistantPreview peek off Store construct so time-to-first-paint stays envelope-only. Implemented on coder/fork-fork-fork-boot-600-ms-synchronous-j-3f0c95.

  5. currentbits commented on Aug 22, 2026

    @currentbits
    OwnerAuthor

    Landed on main in the 2026-08-22 backlog merge (2d33d30..bf7c4dc, released as nightly nightly-202608220926-bf7c4dc).

    Evidence on main: electron/jsonEnvelope.js; messagesByThread hydrates lazily per thread

    The branch had been finished for a while but was never merged; verification after landing: typecheck clean, vite build ok, core 38/38, renderer 1468/1468, memory 204/204, electron 1848/1848.

  6. added
    plan:done
    and removed
    plan:doing
    on Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions