Skip to content

perf(desktop): only persist the background colour when it changes - #49770

Merged
Hona merged 1 commit into
v2from
settings-write-skip
Sep 19, 2026
Merged

Hona merged 1 commit into
v2from
settings-write-skip

Conversation

@Hona

@Hona Hona commented Sep 18, 2026

Copy link
Copy Markdown
Member

Main-process CPU profile of a packaged launch, bottom-up from fsync:

39.5 ms  fsync ← fsyncSync ← atomically ← conf.writeFileSync ← conf.set store ← conf.set
         ← setBackgroundColor (windows/appearance.ts) ← AppSetBackgroundColor IPC handler

DesktopEffects in the renderer sends --background-base on every boot (and on theme change). setBackgroundColor unconditionally called getStore().set(...), and electron-store rewrites and fsyncs the whole settings file on each set — even when the value was already #121212. That's ~40 ms of blocked main thread exactly while the renderer is waiting on IPC for its persisted state, plus one disk write per launch.

  • Persist only when the colour differs from the current value
  • Theme changes still write as before

Measured with bun run bench:startup (#49758): packaged v2 build, isolated home, warm service, 6 launches, median.

baseline this PR
opencode.settings rewritten per launch yes no
renderer process → first paint 364 ms 340 ms
renderer process → shell visible 450 ms 433 ms

The renderer reports its theme background over IPC on every boot, and
electron-store rewrites and fsyncs opencode.settings on each set. That
blocked the main thread for ~40 ms while the renderer was waiting on
IPC during startup, for a value that had not changed.
@Hona
Hona requested a review from Brendonovich as a code owner September 18, 2026 13:14
Copilot AI lite review requested due to automatic review settings September 18, 2026 13:14

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 merged commit dfde462 into v2 Sep 19, 2026
10 checks passed
@Hona
Hona deleted the settings-write-skip branch September 19, 2026 00:34
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