babel / babel/babel

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

Open
#9,383 6 comments 5 reactions 1 assignee Claimed by @grantlouisherman View on GitHub
help wanted
Dominant language
TypeScript
Stars
44k
Forks
6k
Avg merge
5d 15h
Merged PRs (30d)
23

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)**

```js
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.