-
Notifications
You must be signed in to change notification settings - Fork 17.3k
Atom startup perf #9720
Description
Question: Why do I see a blank screen for multiple seconds 🕙 when booting a new atom session?
TLDR:
Most of the startup time is spent requiring modules and deadlocked in node.js execution before the initial paint in the browser is ever fired, resulting in slow feeling startup experience for end users, by potentially bundling all of the deps into one file there could be a sizeable perf savings.
Over the past week a few people have asked me to take a look at why atom’s startup time takes multiple seconds.
Being as atom is a hybrid node + electron (web) app I thought that it would make for a an interesting perf analysis to see the relationship of how node.js perf impacts the dependent web render side of thing ... well it ended up being exactly what I expected.. quite interesting.
To get a look at what was happening inside of atom required a few special tools, however since atom has a built in dev tools (command option i) it is easy to dump all of the profiling info right out of atom and import the traces into the newest version of devtools (inside of canary)
Tools
- canary! https://www.google.com/chrome/browser/canary.html (v49.0.2569.0 at the time of writing this)
- turn on the experimental dev tools under flags

- canary super experimental mode
The investigation 🔍
Once our tools were setup it was pretty simple to reproduce the test case, open up atom (in my case I built atom off of the tip of tree bcbb8c0) and open up the built in inspector and then hit command + R to trip a reload of atom. Now we are cooking with our timeline and profile dumps -- onto looking at what the timeline is showing us
Looking at the initial chunk before load is called it looks like we are being bogged down in simply requiring all of the modules that atom uses.. before we do any work at all we spend over 70ms at initial boot just in require module calls
Once the initial window.onload we get kicked into another 167ms of module loads before we even have even started setting up our new atom env (which does all of the painting)
And then around 500~ ms we seen the initial non-blank paint happen. At this point we have a pretty good picture of where the time is being spent on startup in the most ideal of situations (where a user does not have a pile of plugins or custom themes to further slow it down).
Looking into the work that is happening inside of setup window prior to painting we can break the 200+ ms down into specific segments of work that perhaps could happen after the initial paint, thus prioritizing when we draw the UI to the user before loading additional modules and doing work that is blocking
So with all of this information, it is clear that we are paying a significant cost due to the number of modules that are being required and time being spent inside of the require load dance prior to even trying to run any JS. (one fun downfall of putting all of the requires at the top of all of your JS files). The profile deep dive does raise the question of how much of this require work can be pushed off to happen async after the initial paint? Would it be possible to precompile all of the JS used in atom into a single blob to avoid the fixed require cost? How much of a progressive experience is acceptable for plugins? can we load them in after the fact or will this be too strange?
Overall this profile shows that there is nothing that atom is doing wrong, there are just some interesting performance costs that most developers we never run into or care about given that the difference between a 200ms and 500ms startup is not something to spend time reworking the world around, however for a text editor where users are constantly opening new windows it can become quite noticeable and annoying.
Welp, hopefully this is helpful! ✨
Thanks again to @paulirish and all of the awesome folks at github and atom :)










