Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: transformFromAstSync leaks memory #13970

Closed
1 task done
JLHwung opened this issue Nov 16, 2021 · 3 comments · Fixed by #14583
Closed
1 task done

[Bug]: transformFromAstSync leaks memory #13970

JLHwung opened this issue Nov 16, 2021 · 3 comments · Fixed by #14583
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: core

Comments

@JLHwung
Copy link
Contributor

JLHwung commented Nov 16, 2021

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

for (let i = 0; i < 1e7; i++) {
    ast = babel.transformFromAstSync(ast, src, {
      configFile: false,
      ast: true,
    }).ast;
  }

For a complete reproduction, see https://github.com/JLHwung/babel-transform-from-ast-leak

Configuration file name

No response

Configuration

N.A.

Current and expected behavior

Current: The memory usage rises beyond 2GB

Expected: The memory usage should be stable during repetitive transformFromAstSync calls.

Environment

System:
OS: macOS 12.0.1
Binaries:
Node: 17.0.1 - /opt/homebrew/bin/node
Yarn: 1.22.17 - /opt/homebrew/bin/yarn
npm: 8.1.0 - /opt/homebrew/bin/npm
npmPackages:
@babel/core: ^7.16.0 => 7.16.0

Possible solution

No response

Additional context

Found this issue when running jest --detect-leaks in the Babel codebase.

transformFromAstAsync and transformFromAst are also affected.

When switching transformFromAstSync to transformSync, the memory leakage can not be reproduced.

@babel-bot
Copy link
Collaborator

Hey @JLHwung! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Nov 16, 2021

Does it leak if you pass cloneAST: false?

@JLHwung
Copy link
Contributor Author

JLHwung commented Nov 16, 2021

Does it leak if you pass cloneAST: false?

Nice catch! The leak is gone when closeInputAst is disabled. However this option is enabled by default.

It is likely that after cloneDeep is performed, the new AST object still contains reference to the old AST object which prevents them from being collected.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 20, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants