atom/atom — pull request #3453 by kevinsawicki (2014-09-04 18:59:33+00:00)
Title: Lower browser process startup time

Taking a look at the browser process startup time.

This is the time between when atom-shell require's Atom's [main](https://github.com/atom/atom/blob/d8be03850bb39f2b8472261fb47c610bbdfb509c/src/browser/main.coffee#L1) file and the [first window is created](https://github.com/atom/atom/blob/d8be03850bb39f2b8472261fb47c610bbdfb509c/src/browser/main.coffee#L51).

This includes the time taken to parse the command line arguments, create the native windows, setup the crash reporter, setup the system menus, and start the auto updater.

I added a new benchmark that starts the app 10 times and averages the app startup time.

The results for me at the start of this branch were:

```
Startup Runs: 10
First run time: 180ms
Max time: 196ms
Min time: 173ms
Average time: 181ms
```

And the results now are:

```
Startup Runs: 10
First run time: 138ms
Max time: 138ms
Min time: 117ms
Average time: 121ms
```

This is on a Macbook Pro on OS X 10.8.5 with 2.6 Ghz Intel Core i7 processors and 16 GB of memory.

### Running the benchmark

I'd be curious what results other people see so if you want to post your before and after results do the following:

* Pull down this branch
* Do a `git checkout fbeb9ec` to checkout the commit before the changes were made
* Run `script/build`
* Run `benchmark/browser-process-startup.coffee` to see the *before* results
* Do a `git checkout ks-lower-browser-process-startup-time` to checkout the latest commit
* Run `script/build` again
* Run `benchmark/browser-process-startup.coffee` to see the *after* results

### What changed

Much of the time spent on my machine was doing `require`s of lots of files that weren't used until later on or possible never at all, but the requires were at the top of the files and so the first window wasn't being shown until all these requires were complete.

Many of these were moved to be required right before use in response to an event or request from a render process.