Skip to content

perf(desktop): show the previous shell while the renderer boots - #49890

Closed
Hona wants to merge 1 commit into
devfrom
prepaint
Closed

Hona wants to merge 1 commit into
devfrom
prepaint

Conversation

@Hona

@Hona Hona commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

Draft, for analysis. Item 4 of the restructure: the first window shows the shell from the previous run while the renderer boots.

sequenceDiagram
  participant M as main (entry)
  participant W as window
  participant R as renderer
  participant B as main (bundle + layers)
  M->>W: create + show (195 ms)
  M->>R: load index.html?early=<id> — no scripts, snapshot in #oc-prepaint
  M->>B: import("./desktop")
  R-->>R: CSS, fonts, snapshot DOM ready (~320 ms)
  B->>R: releaseRenderer: append the module scripts, drop the query
  R->>R: app boots, mounts under the snapshot
  R->>R: readyToReveal → remove #oc-prepaint (no splash, no fade)
  R->>B: WindowSavePrepaint(sanitized #root) once idle
Loading
  • windows/serve.ts serves oc:// without Effect so the entry module can register it before the bundle; index.html?early=<id> is the same document minus its <script type=module> tags, with prepaint-<id>.html (version-tagged, next to the window-state JSON) injected inert after #root.
  • windows/serve.ts#releaseRenderer appends the scripts with async = false (runtime chunk stays first) and history.replaceState drops the query so a reload gets the full document.
  • The RPC MessagePort is now pulled by the renderer (window.electron.requestRpcPort()) instead of pushed on did-finish-load, which for this document fires before the scripts and the IPC layer exist.
  • renderer/startup/prepaint.ts captures #root: strips scripts, dialogs, menus, editors, ids, hrefs and handlers, blanks inputs, copies only the <symbol>s the shell uses; ≤ 1 MB.
  • With a snapshot present the startup splash and its 300 ms fade are not rendered; the snapshot is removed at the moment the overlay used to start fading.

Expected vs actual (warm, restored draft tab, interleaved, 5 runs, medians)

Expected: the user's UI on screen at ~350 ms instead of a colour at 195 and a splash at ~650; everything else unchanged.

ms since spawn v2 this PR Δ
main bundle evaluated 359 631 +272
app starting 537 743 +206
service ready 742 859 +117
renderer process 634 256 −378
snapshot DOM ready (domInteractive) — 384
first pixels ≠ background (screenPainted) 780 (splash) 1261 (the UI) +481
UI on screen and stable (screenSettled) 1529 1261 −268
shell DOM 1081 1142 +61
renderer idle 1634 1687 +53
main CPU 1359 1217 −142

Actual, honestly: the snapshot itself is never on screen. Its DOM is ready at ~380 ms but its first frame is not presented before the real UI replaces it. The UI still reaches the screen 270 ms earlier because the splash fade is gone and the shell's GPU shaders compile earlier. The early renderer costs the main thread ~200 ms (bundle evaluation 114 → 349 ms with a renderer competing for the UI thread).

Two things found on the way (bench harness now measures them)

  • shellVisible was never what the user sees. The DOM says 872–1081 ms; the screen shows the interface at ~1300–1530 ms. Two reasons: the 300 ms splash fade, and ~30 Skia shader programs compiled through ANGLE/D3D on the GPU main thread (~15 ms each, serialised) the first time the shell rasterizes — the GPU thread is blocked for ~480 ms and no frame is presented meanwhile.
  • The GPU shader disk cache never persists. GPUCache/index has 0 entries after 40 s runs and graceful exits in the bench profile; every launch recompiles (GrShaderCache::load misses = stores, every run). If that cache worked, the shell would be on screen ~450 ms earlier on every launch, with or without this PR. Worth its own investigation.

Measured with the screen-sampling harness from #49894.

The first window now loads its document the moment Electron is ready:
the same index.html without its module scripts, plus a sanitized copy of
the shell captured at the end of the previous run. The renderer process,
the stylesheet and the fonts are ready while the main bundle and the
layers load, and the scripts are added when the window is adopted.

The renderer asks for its RPC MessagePort instead of receiving one on
did-finish-load, since that event fires before the scripts exist.

The startup splash and its 300 ms fade are skipped when a snapshot is
present; the snapshot is removed when the interface would have been
revealed, and re-captured once idle and after route changes.
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant