Repository navigation
perf(desktop): remember window bounds without electron-window-state - #49792
Merged
Merged
Conversation
electron-window-state pulls jsonfile, mkdirp and the deep-equal tree (~25 packages) into every launch: 26 ms of CommonJS requires in the startup trace before any of our code ran. The desktop only needs the saved bounds, the maximized / fullscreen flags and a manage() that tracks the window until it closes. Implement that in window-state.ts with the same JSON file and validation rules (bounds must still fit a current display, otherwise default size on the primary display) so existing profiles restore where they were. Packaged build, warm service, median of 6 launches: first main-process log line 401 -> 380 ms after spawn.
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
Track window bounds and the maximized/fullscreen flags in the same JSON file electron-window-state wrote, so existing profiles restore where they were, without loading the package at startup. Ported from upstream 4facc03; the module is named window-bounds because Forge already has a window-state module. No measurable startup change on a dev build. Upstream: anomalyco/opencode@4facc03371 (anomalyco#49792)
divyanshusingh2903
added a commit
to divyanshusingh2903/forge
that referenced
this pull request
Oct 21, 2026
Track window bounds and the maximized/fullscreen flags in the same JSON file electron-window-state wrote, so existing profiles restore where they were, without loading the package at startup. Ported from upstream 4facc03; the module is named window-bounds because Forge already has a window-state module. No measurable startup change on a dev build. Upstream: anomalyco/opencode@4facc03371 (anomalyco#49792)
divyanshusingh2903
added a commit
to divyanshusingh2903/forge
that referenced
this pull request
Oct 21, 2026
Track window bounds and the maximized/fullscreen flags in the same JSON file electron-window-state wrote, so existing profiles restore where they were, without loading the package at startup. Ported from upstream 4facc03; the module is named window-bounds because Forge already has a window-state module. No measurable startup change on a dev build. Upstream: anomalyco/opencode@4facc03371 (anomalyco#49792)
divyanshusingh2903
added a commit
to divyanshusingh2903/forge
that referenced
this pull request
Oct 21, 2026
…nomalyco#49792) Track window bounds and the maximized/fullscreen flags in the same JSON file electron-window-state wrote, so existing profiles restore where they were, without loading the package at startup. Ported from upstream 4facc03; the module is named window-bounds because Forge already has a window-state module. No measurable startup change on a dev build. Upstream: anomalyco/opencode@4facc03371 (anomalyco#49792)
divyanshusingh2903
added a commit
to divyanshusingh2903/forge
that referenced
this pull request
Oct 21, 2026
…nomalyco#49792) Track window bounds and the maximized/fullscreen flags in the same JSON file electron-window-state wrote, so existing profiles restore where they were, without loading the package at startup. Ported from upstream 4facc03; the module is named window-bounds because Forge already has a window-state module. No measurable startup change on a dev build. Upstream: anomalyco/opencode@4facc03371 (anomalyco#49792) 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:The desktop uses
x/y/width/heightfrom the saved state andmanage(win), which restores maximized/fullscreen and tracks the window until it closes. That is ~100 lines; the dependency'sdeep-equaltree is what made it 26 ms on every launch.windows/window-state.ts:readWindowState(file)+resolveWindowState(saved, defaults, displays)— same rules as the library: integer bounds required; bounds must still fit inside one current display, otherwise default size at (0,0) on the primary display; a saved maximized/fullscreen flag survives without bounds; anything unusable → defaults with no position (Electron centres)manageWindowState(win, file, state, displays)— maximize/fullscreen on restore, debounced bounds capture onresize/movewhile the window is in its normal state, final write onclosed(before the app's ownclosedhandler that deletes the file for deliberately closed windows, same order as before)window-state-<id>.json) and same compact JSON shape, so existing profiles restore where they weredisplaysis injected, so the resolution rules are unit-tested without Electronelectron-window-statefrompackage.jsonMeasured with
bun run bench:startup(#49758): packagedv2build, isolated home, warm service, median of 6 launches.app starting)Companion to #49791 (electron-store), which removes the other heavy CommonJS import on the same path.