This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Repository navigation
Minimize synchronous I/O during startup - #13949
Merged
Merged
Conversation
added 4 commits
March 7, 2017 10:54
When accessing objects in the main process via the `remote` module, Electron returns proxy objects that are references to the original ones. This means that trying to access a remote object's property or function results in a synchronous message exchange with the main process. In Atom core we frequently access the load settings coming from the main process, especially during startup. This caused a lot of synchronous I/O which was blocking the renderer process for several milliseconds. With this commit, instead of exposing load settings as a JavaScript object, we serialize them to JSON in the main process and parse them back to a JavaScript object in the renderer processes. This allows us to get a full copy of the object locally and pay for I/O just once when retrieving load settings from the main process for the first time.
This commit will register the `display-added` and `display-removed` events only once in the main process in order to disable zoom (see #11345) directly instead of unnecessarily paying for I/O in the renderer process during startup.
This will still notify render processes when such events are triggered without, however, incurring the additional cost of synchronously retrieving a `BrowserWindow` (and its properties) via `remote` during startup.
Instead of using `localStorage` to store and retrieve the project history, with this commit we will use `StateStore` so that we can retrieve state asynchronously without blocking Atom during startup.
Contributor
|
I'm okay with the api change as you say it's quite new and nobody else is using it just yet. However switching backing store is going to effectively wipe-out current history. This is a real pain for anyone who uses it today - I think we need a fallback where if it finds no project history on load then it looks to the old storage to do a one-off import. (You can delete the old importProjectHistory method that I left in there) |
Closed
1 task done
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
When Atom boots up it is extremely crucial to perform as little synchronous operations as possible in order to minimize startup time. This pull request does so by:
Exposing load settings to
BrowserWindows as JSON.When accessing objects in the main process via the
remotemodule, Electron returns proxy objects that are references to the original ones. This means that trying to access a remote object's property or function results in a synchronous message exchange with the main process.In Atom core we frequently access the load settings coming from the main process, especially during startup. This caused a lot of synchronous I/O which was blocking the renderer process for several milliseconds.
With this pull request, instead of exposing load settings as a JavaScript object, we serialize them to JSON in the main process and parse them back to a JavaScript object in the renderer processes. This allows us to get a full copy of the object locally and pay for I/O only once when retrieving load settings from the main process for the first time.
Disabling zoom in the main process rather than in the renderer process.
With this pull request we will register the
display-addedanddisplay-removedevents only once in the main process in order to disable zoom (seeDisable zoom every time a display gets added or removed #11345) directly instead of unnecessarily paying for I/O in the renderer process during startup.
Registering enter/leave fullscreen events in the main process rather than in the renderer process.
This will still notify render processes when such events are triggered without, however, incurring the additional cost of synchronously retrieving a
BrowserWindow(and its properties) viaremoteduring startup.Replacing
localStoragewithStateStoreinHistoryManager.Instead of using
localStorageto store and retrieve the project history, with this pull request we will useStateStoreso that we can retrieve state asynchronously without blocking Atom during startup. @damieng: I think this slightly changes the publicclearProjectsAPI by making it asynchronous. Considering the recent introduction of the API and its low adoption (I couldn't find anyone using it in packages), I believe this might be negligible; if you have any concern about it, though, please don't hesitate to raise them up.These improvements are particularly evident during the construction of an
AtomEnvironmentinstance. This is how a typical chart of that code path looks like today on master:After removing all the synchronous I/O, the same code path looks like the following:
On average, with these changes we save
~ 40msfor the construction ofAtomEnvironment. Moreover, the experience should be snappier across all the code paths because we won't pay any additional cost to retrieve load settings and to save project history state anymore.The next step will involve building an
AtomEnvironmentinstance right inside the snapshot (as opposed to doing so at runtime) and thus potentially save 80-90% of the remaining~ 80msobserved after the changes introduced by this pull request./cc: @atom/maintainers