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

Reduce the number of modules loaded by the main process on startup #19269

Closed

Description

@rafeca

Summary

We want to reduce the number of JS modules that get loaded during the startup time by the Atom main process in order to improve the startup time.

In some situations, we can just deduplicate dependencies (or remove unneeded dependencies) to get a net reduction of loaded modules, in some other situations we may need to delay the loading of modules (which would just delay the cost to whenever that module is used).

Hypothesis

By delaying the loading (and parsing/evaluation) of non-essential JS modules, we can speed up the startup of Atom

Context

Atom timing data

Currently, the Shell load time (which is one part of the startup time that corresponds to the time it takes from the first JS file gets executed in the main process until the Atom window gets opened) is the main contributor to the Atom startup time.

For the last 5 Atom versions, the shell load time on real users have been around ~1.1s (median time), while the window open time has been around ~160ms.

Current list of required modules

Currently, Atom's main process loads 396 JS modules before starting a new window (~200 of them are unique).

There's some duplication of modules (fs-extra) and some modules that shouldn't be needed since they are provided by nodejs core library (nodegit-promise, promisify-node).

How to debug the required modules on startup

I've used some hacky code to locally plug into the require system of the main process and store each single loaded module.

To do so, I've added the following logic at the very top of the main process start file:

const Module = require('module')
const origRequire = Module._load

const modules = new Set()
const startTime = Date.now()

const rootPath = require('path').join(__dirname, '..', '..')
function pathRelative(input) {
  return input.replace(rootPath, '.')
}

Module._load = function (moduleId, from) {
  const modulePath = pathRelative(Module._resolveFilename(moduleId, from))

  if (modulePath.startsWith('./')) {
    // Only log non-core JS files.
    modules.add(
      modulePath + ' (required by ' + pathRelative(from.id) + ')'
    )
  }

  return origRequire.apply(this, arguments)
}

global.__debugSaveStartupModules = () => {
  modules.add('-------')
  modules.add('Startup time: ' + (Date.now() - startTime))

  require('fs').writeFileSync('/Users/rafeca/tmp/modules.txt', [...modules].join('\n'))
}

And then called global.__debugSaveStartupModules() when the Atom window gets opened).

Activity

  1. added
    FY2019Q5 atom perf
    on May 6, 2019
  2. stale commented on May 6, 2020

    @stale

    Thanks for your contribution!

    This issue has been automatically marked as stale because it has not had recent activity. Because the Atom team treats their issues as their backlog, stale issues are closed. If you would like this issue to remain open:

    1. Verify that you can still reproduce the issue in the latest version of Atom
    2. Comment that the issue is still reproducible and include:
      • What version of Atom you reproduced the issue on
      • What OS and version you reproduced the issue on
      • What steps you followed to reproduce the issue

    Issues that are labeled as triaged will not be automatically marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FY2019Q5 atom perfstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions