Repository navigation
perf(desktop): replace electron-store with a plain JSON settings store - #49791
Merged
Merged
Conversation
The main process only calls get, set and delete on electron-store, but importing it pulled conf, ajv, ajv-formats, semver and their trees into every launch: ~36 ms of CommonJS requires in the startup trace before any of our code ran, plus an fsync on every write. Read the same tab-indented JSON file once and rewrite it atomically instead. Existing profiles and older builds keep working because the file format is unchanged; an unreadable file is set aside as .corrupt rather than blocking startup. Packaged build, warm service, median of 6 launches: first main-process log line 401 -> 353 ms after spawn.
This was referenced Sep 18, 2026
jinhuang712
pushed a commit
to jinhuang712/opencode
that referenced
this pull request
Sep 26, 2026
3 of 6 tasks
divyanshusingh2903
added a commit
to divyanshusingh2903/forge
that referenced
this pull request
Oct 21, 2026
Read and write the same tab-indented JSON file electron-store used, so existing profiles and older builds are unaffected, without loading electron-store and its schema validation at startup. An unreadable file is set aside instead of blocking startup. Ported from upstream f6353a4. The electron-store dependency is left in package.json so the lockfile is unchanged. On a dev build the window's first server request moves from ~1.1s to ~1.04s. Upstream: anomalyco/opencode@f6353a48b5 (anomalyco#49791)
divyanshusingh2903
added a commit
to divyanshusingh2903/forge
that referenced
this pull request
Oct 21, 2026
Read and write the same tab-indented JSON file electron-store used, so existing profiles and older builds are unaffected, without loading electron-store and its schema validation at startup. An unreadable file is set aside instead of blocking startup. Ported from upstream f6353a4. The electron-store dependency is left in package.json so the lockfile is unchanged. On a dev build the window's first server request moves from ~1.1s to ~1.04s. Upstream: anomalyco/opencode@f6353a48b5 (anomalyco#49791)
divyanshusingh2903
added a commit
to divyanshusingh2903/forge
that referenced
this pull request
Oct 21, 2026
Read and write the same tab-indented JSON file electron-store used, so existing profiles and older builds are unaffected, without loading electron-store and its schema validation at startup. An unreadable file is set aside instead of blocking startup. Ported from upstream f6353a4. The electron-store dependency is left in package.json so the lockfile is unchanged. On a dev build the window's first server request moves from ~1.1s to ~1.04s. Upstream: anomalyco/opencode@f6353a48b5 (anomalyco#49791)
divyanshusingh2903
added a commit
to divyanshusingh2903/forge
that referenced
this pull request
Oct 21, 2026
…anomalyco#49791) Read and write the same tab-indented JSON file electron-store used, so existing profiles and older builds are unaffected, without loading electron-store and its schema validation at startup. An unreadable file is set aside instead of blocking startup. Ported from upstream f6353a4. The electron-store dependency is left in package.json so the lockfile is unchanged. On a dev build the window's first server request moves from ~1.1s to ~1.04s. Upstream: anomalyco/opencode@f6353a48b5 (anomalyco#49791)
divyanshusingh2903
added a commit
to divyanshusingh2903/forge
that referenced
this pull request
Oct 21, 2026
…anomalyco#49791) Read and write the same tab-indented JSON file electron-store used, so existing profiles and older builds are unaffected, without loading electron-store and its schema validation at startup. An unreadable file is set aside instead of blocking startup. Ported from upstream f6353a4. The electron-store dependency is left in package.json so the lockfile is unchanged. On a dev build the window's first server request moves from ~1.1s to ~1.04s. Upstream: anomalyco/opencode@f6353a48b5 (anomalyco#49791) Co-authored-by: Luke Parker <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chromium startup trace of a packaged launch, browser process,
require()events (ms since trace start):The main process uses three methods of
electron-store—get,set,delete— on two tab-indented JSON files (opencode.settings,opencode.updater). Importing it cost ~36 ms of CommonJS loading on every launch before any of our code ran, andconffsyncs the whole file on eachset.This replaces it with
createSettingsStore(file):JSON.stringify(data, null, "\t")via temp file + rename — byte-identical format, so existing profiles and older builds keep workinggetStore(name)keeps its signature and lazy construction (userData is set after import)<file>.corruptand treated as empty instead of failing startup (confwould throw)set(key, undefined)still throws likeconfdidelectron-storefrompackage.json(andconf,ajv,ajv-formats, … from the bundle)Measured with
bun run bench:startup(#49758): packagedv2build, isolated home, warm service, median of 6 launches.app starting)Independent of #49770 (skip unchanged background-colour writes), which still avoids a pointless write per launch.