babel/babel

creating `OptionManager` instances is super slow in @babel/register

Open

#9,383 opened on Jan 22, 2019

View on GitHub
 (6 comments) (5 reactions) (1 assignee)TypeScript (5,826 forks)batch import
help wanted

Repository metrics

Stars
 (43,894 stars)
PR merge metrics
 (Avg merge 4d 4h) (30 merged PRs in 30d)

Description

Bug Report

Current Behavior

The first thing @babel/register does is create a new OptionManager:

https://github.com/babel/babel/blob/f2af6c1170ebbea22bd29a2bae01efaec800dfe9/packages/babel-register/src/node.js#L41

It does that for all files, even things that I want to explicitly ignore, such as node_modules. Even though I use the option babelrc: false, which should tell it to not resolve .babelrc files via the filesystem.

For a quite large app we have, creating these OptionManager instances alone accounts for ~20 seconds of our app startup, which would normally start in ~4 seconds with precompiled code, without the register hook.

Expected behavior/code

Things should be fast. :-)

Babel Configuration (.babelrc, package.json, cli command)

register({
  babelrc: false,
  extensions: ['.js', '.ts', '.tsx'],
    ignore: [/node_modules/, /dist/, /\.d\.ts$/],
    sourceMaps: 'both',
    presets: [
      [
        '@babel/preset-env',
        {
          shippedProposals: true,
          targets: { node: true },
          modules: 'commonjs',
          useBuiltIns: 'entry',
        },
      ],
      '@babel/preset-react',
      '@babel/preset-typescript',
      '@babel/preset-flow',
    ],
    plugins: ['@babel/plugin-proposal-class-properties', '@babel/plugin-syntax-dynamic-import', 'dynamic-import-node'],
})

Environment

  • Babel version(s): 7.2.2
  • Node/npm version: node 8
  • OS: linux
  • Monorepo: yes, lerna
  • How you are using Babel: register

Possible Solution

  • It should use a pre-cached version of OptionManager when I use babelrc: false
  • It should maybe cache OptionManager instances on a per-directory basis
  • It should use the ignore regexps earlier to avoid creating the OptionManager instances

Contributor guide