Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Minimize synchronous I/O during startup - #13949

Merged
as-cii merged 7 commits into
masterfrom
as-minimize-startup-sync-io
Mar 10, 2017
Merged

as-cii merged 7 commits into
masterfrom
as-minimize-startup-sync-io

Conversation

@as-cii

@as-cii as-cii commented Mar 7, 2017 •

Copy link
Copy Markdown
Contributor

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:

  1. Exposing load settings to BrowserWindows as JSON.

    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 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.

  2. Disabling zoom in the main process rather than in the renderer process.

    With this pull request we will register the display-added and display-removed events only once in the main process in order to disable zoom (see
    Disable zoom every time a display gets added or removed #11345) directly instead of unnecessarily paying for I/O in the renderer process during startup.

  3. 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) via remote during startup.

  4. Replacing localStorage with StateStore in HistoryManager.

    Instead of using localStorage to store and retrieve the project history, with this pull request we will use StateStore so that we can retrieve state asynchronously without blocking Atom during startup. @damieng: I think this slightly changes the public clearProjects API 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 AtomEnvironment instance. This is how a typical chart of that code path looks like today on master:

screen shot 2017-03-07 at 11 10 00

After removing all the synchronous I/O, the same code path looks like the following:

screen shot 2017-03-07 at 11 05 29

On average, with these changes we save ~ 40ms for the construction of AtomEnvironment. 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 AtomEnvironment instance right inside the snapshot (as opposed to doing so at runtime) and thus potentially save 80-90% of the remaining ~ 80ms observed after the changes introduced by this pull request.

/cc: @atom/maintainers

Antonio Scandurra 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.
@damieng

damieng commented Mar 7, 2017

Copy link
Copy Markdown
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)

@winstliu winstliu mentioned this pull request Mar 8, 2017
@as-cii
as-cii merged commit 11961b0 into master Mar 10, 2017
@as-cii
as-cii deleted the as-minimize-startup-sync-io branch March 10, 2017 14:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants