Skip to content

creating OptionManager instances is super slow in @babel/register #9383

@Swatinem

Description

@Swatinem

Bug Report

Current Behavior

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

const opts = new OptionManager().init(

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

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions