Skip to content

First paint waits on the whole boot chain: createWindow() is the last thing whenReady does #618

Closed

Description

@currentbits

createWindow() is the last statement of app.whenReady() (electron/main.js:449). Everything in the 234 lines above it runs before a single pixel exists, and most of it does not need a window to be absent.

What sits in front of first paint

Measured on the live workspace (2026-08-20, 545 threads, 170 MB store):

new Store(storePath)                main.js:293
  fs.readFileSync   170 MB           234 ms   sync
  JSON.parse                         330 ms   sync
  fs.copyFileSync → .bak (170 MB)     62 ms   sync
                                    ------
                                     626 ms of blocking main-process work

await memorySupervisor.start()      main.js:284
  probeHealth on an existing server, HEALTH_TIMEOUT_MS = 1000 ms budget
  (memory-sup.js:12, awaited at main.js:284 despite the "never block app start" comment)

lastStatus Map build over 545 threads   main.js:296-299
await import(core)                      main.js:248
legacy userData migration probes        main.js:255-268
grok/user MCP config sync               main.js:430-447

None of that produces UI. The window is created with backgroundColor: "#0b0e14" and no ready-to-show gate, so the user gets a dark rectangle only after the whole chain completes.

The .bak copy deserves its own mention: 170 MB is read and re-written to disk on every single launch, synchronously, on the critical path, purely as a rolling backup (store.js:1086).

Fix

  1. createWindow() first. Create and load the window at the top of whenReady, then do the store load and supervisor start. The renderer already handles an empty initial state (it fetches lists on mount); a boot:ready push when the store is up is the only wiring needed.
  2. Do not await memorySupervisor.start(). The comment at main.js:283 already says "Never block or fail app start on memory supervision" — the await on the next line contradicts it. Fire it and let it settle; every consumer already tolerates memory being absent.
  3. Move the .bak copy off the critical path. It is a rolling backup of a file that was just read successfully; doing it after first paint (or on the first idle flush) loses nothing.

#225 removes the largest chunk of this by shrinking the blob, and should land first — but the ordering is wrong independently of size, and 1 and 2 are a handful of lines that hold under any future store shape.

While in there: waitForHealth (memory-sup.js:803) has no callers anywhere in electron/. Either the spawn path was meant to wait on it and does not, or it is dead and should go.

Tests

  • A boot with a deliberately slow store load still creates the window before the load resolves (assert ordering via the existing main-process seams).
  • memorySupervisor.start() rejecting or hanging does not delay createWindow().
  • Store load still writes the .bak exactly once per boot, just not before the window.

Related

#225 (shrinks the 626 ms, does not fix the ordering), #418 (startup umbrella — enableCompileCache, Slack-style boot data; module.enableCompileCache() is still absent from electron/), #617 (the other end: what the renderer does once it is up), #124.

Activity

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

    @currentbits
    OwnerAuthor

    Implemented in this worktree:

    • createWindow() runs at the top of whenReady via bootFirstPaint (menu first, then the window, then a yield so Chromium can paint).
    • memorySupervisor.start() is no longer awaited; hang/reject cannot stall first paint.
    • Store .bak copy is setImmediate after a successful load, not on the constructor’s sync path.
    • Renderer refetches lists on a boot:ready push once IPC handlers exist.
    • Dead waitForHealth removed; spawn already polls inline because the port can move.

    Tests: electron/test/boot.test.js, store .bak deferral, appWiring refetch.

  3. 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/boot.js bootFirstPaint; window paints before store load

    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.

  4. 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