How is package startup time calculated?


#1

This seems to be a fuzzy area as evidence by this discussion I had with the maintainer of the update-packages package.

How is startup time calculated? Why does the calculated time fluctuate so much? How can package contributors optimize their startup time?

Feels like this would be interesting documentation for contributors to read through.


#2

The time display in the settings view is the time to load and activate the plugin.

This includes reading, parsing, and registering grammars, keymaps, menus, stylesheets, and properties as well as requiring the package’s main class and calling activate on it.

This can fluctuate the very first time the package ever runs since the CoffeeScript will be compiled for the first time and cached to /tmp.

You can optimize startup time in your package by only requiring the bare minimum of files needed in your activate method. This often involves doing lazy requires for things that are only needed under certain conditions or usage.

You can see examples of this in the settings view package: https://github.com/atom/settings-view/blob/master/lib/index.coffee

The main view class is really large and requires many sub views classes, but the view class is only required when the settings view is actually opened making it affect startup time very minimally.