Skip to content

perf(desktop): boot the renderer alongside the main bundle - #50108

Merged
Hona merged 1 commit into
v2from
early-renderer-load
Sep 20, 2026
Merged

Hona merged 1 commit into
v2from
early-renderer-load

Conversation

@Hona

@Hona Hona commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Bottom of a 7-PR stack that gets the desktop window from "visible" to "shell rendered" in ~210 ms instead of ~660 ms. Each layer is independently reviewable; the numbers below are for the whole stack.

PR what
1 this renderer boots the tick the window exists; entry chunk wires oc://, permissions, navigation, headers; shell gate values in argv
2 #50109 main waits for the renderer's asset burst before evaluating its bundle
3 #50110 renderer's initial module graph is one chunk
4 #50111 crash reporter, onboarding scan, log cleanup, certs/proxy/netlog, CLI resolve, palette, service probe off the path
5 #50112 renderer speaks the RPC wire format directly; Effect runtime out of its initial graph
6 #50113 preload hands the window its persisted stores; first render is the hydrated one
7 #50114 renderer CPU profiles attributed to source files (tooling)
gantt
  dateFormat X
  axisFormat %L
  section before
  entry → ready               :a1, 0, 134
  window shown                :a2, 134, 192
  main bundle + layers        :a3, 192, 484
  renderer boot               :a4, 484, 583
  wait for port + 4 RPCs      :a5, 583, 889
  section after
  entry → ready               :b1, 0, 133
  window shown + loadURL      :b2, 133, 186
  renderer boot (main idle, serving assets) :b3, 186, 281
  main bundle + layers        :b4, 314, 448
  compile + evaluate + hydrated render :b5, 281, 390
Loading

This layer: createEarlyWindow registers the oc:// handler, permissions, navigation policy and headers itself and calls loadURL in the same tick the window is created. The entry chunk stays Effect-free; the protocol handler reports through console until the logging layer installs a reporter. The window's argv carries firstLaunchPending and defaultServerUrl so the renderer can mount its shell without asking main; the locale is cached in localStorage for the same reason.

// main/index.ts
void app.whenReady().then(() => {
  createEarlyWindow()          // window + loadURL, before the main bundle is even imported
  return import("./desktop")
})

Packaged startup bench (bun run bench:startup), Windows laptop display, warm service, 5 interleaved runs, medians in ms since spawn, v2 vs the full stack:

v2 stack
renderer process starts 468 179
DOM interactive 582 263
shell in DOM (titlebar tab) 853 387
composer editable 853 613
first pixels on screen 573 622
screen settled 1132 945

Window → shell: 664 → 210 ms. First pixels land ~50 ms later than before but as the complete hydrated frame; on stock Electron that instant is set by GPU shader compilation, which the renderer now finishes ahead of (electron/electron#54113 removes that wait).

The first window's renderer used to start after every main-process layer was built and then waited on the IPC port before it could mount. createEarlyWindow now registers the oc:// handler, permissions, navigation policy and headers itself and calls loadURL in the tick the window is created, with the entry chunk kept Effect-free (the protocol handler reports through console until the logging layer installs a reporter). The window's argv carries firstLaunchPending and defaultServerUrl so the renderer mounts its shell without waiting on main; the locale is cached in localStorage for the same reason. Layer marks are reported with layers ready so the startup bench can attribute the time before the port.
@Hona
Hona requested a review from Brendonovich as a code owner September 20, 2026 06:12
Copilot AI lite review requested due to automatic review settings September 20, 2026 06:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Hona
Hona added this pull request to stack #50115 September 20, 2026 06:13
@Hona Hona changed the title early renderer load perf(desktop): boot the renderer alongside the main bundle Sep 20, 2026
@Hona
Hona merged commit 7fc3f68 into v2 Sep 20, 2026
12 checks passed
@Hona
Hona deleted the early-renderer-load branch September 20, 2026 06:16
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
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.

2 participants