Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Babel 7] Improve generator performance#17642

Merged
nicolo-ribaudo merged 4 commits intobabel:7.xbabel/babel:7.xfrom
liuxingbaoyu:perf-generatorliuxingbaoyu/babel:perf-generatorCopy head branch name to clipboard
Jan 16, 2026
Merged

[Babel 7] Improve generator performance#17642
nicolo-ribaudo merged 4 commits intobabel:7.xbabel/babel:7.xfrom
liuxingbaoyu:perf-generatorliuxingbaoyu/babel:perf-generatorCopy head branch name to clipboard

Conversation

@liuxingbaoyu
Copy link
Copy Markdown
Member

@liuxingbaoyu liuxingbaoyu commented Dec 6, 2025

Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Close #17627

This resulted in a 20%+ performance improvement vs v7.26.3 and a ~25% performance improvement vs the latest v7 version.

I did the following to improve performance:

  1. Store generator functions in a Map instead of class prototypes.
  2. Remove the queue.
  3. Reduce calls of charCodeAt.
  4. Reduce node.type comparisons.
  5. Make the identifier extraction logic run only when the source map is enabled.

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Dec 6, 2025

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/60557

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Dec 6, 2025

Open in StackBlitz

commit: 369cfac

@liuxingbaoyu liuxingbaoyu marked this pull request as draft December 12, 2025 12:07
@liuxingbaoyu liuxingbaoyu marked this pull request as ready for review December 15, 2025 19:21
Comment thread babel.config.js
*/
function pluginGeneratorOptimization({ types: t }) {
const generatorNames = [];
fs.globSync(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The globSync is not available in Node.js 6. The Babel config will be invoked by Jest to transform unit tests written in ESM.

@liuxingbaoyu liuxingbaoyu force-pushed the perf-generator branch 2 times, most recently from 22e537f to 666738c Compare December 16, 2025 00:09
@liuxingbaoyu
Copy link
Copy Markdown
Member Author

Benchmark results compared to v7.26.3.

PS F:\babel\benchmark\babel-generator> node --expose-gc .\real-case.mjs
babel-generator/real-case.mjs babel-parser-express.ts @ current: 840 ops/sec ±0.6% 4128 runs (1.211ms)
babel-generator/real-case.mjs babel-parser-express.ts @ baseline: 497 ops/sec ±2.37% 2406 runs (2.079ms)
babel-generator/real-case.mjs jquery-3.6.js @ current: 263 ops/sec ±1.19% 1296 runs (3.861ms)
babel-generator/real-case.mjs jquery-3.6.js @ baseline: 163 ops/sec ±1.83% 798 runs (6.267ms)
babel-generator/real-case.mjs ts-checker.mjs @ current: 28.24 ops/sec ±1.42% 141 runs (36ms)
babel-generator/real-case.mjs ts-checker.mjs @ baseline: 20.69 ops/sec ±2.32% 103 runs (49ms)
babel-generator/real-case.mjs ts-checker.ts @ current: 21.99 ops/sec ±1.56% 110 runs (46ms)
babel-generator/real-case.mjs ts-checker.ts @ baseline: 16.3 ops/sec ±2.14% 81 runs (62ms)
babel-generator/real-case.mjs ts-parser.mjs @ current: 260 ops/sec ±1.03% 1286 runs (3.89ms)
babel-generator/real-case.mjs ts-parser.mjs @ baseline: 163 ops/sec ±1.73% 801 runs (6.244ms)
babel-generator/real-case.mjs ts-parser.ts @ current: 190 ops/sec ±1.36% 934 runs (5.358ms)
babel-generator/real-case.mjs ts-parser.ts @ baseline: 119 ops/sec ±1.96% 584 runs (8.572ms)
babel-generator/real-case.mjs typescript-5.6.2.js @ current: 5.72 ops/sec ±1.44% 64 runs (175ms)
babel-generator/real-case.mjs typescript-5.6.2.js @ baseline: 4.32 ops/sec ±1.65% 64 runs (232ms)

@liuxingbaoyu liuxingbaoyu added PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories pkg: generator labels Jan 2, 2026
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@@ -1,10 +0,0 @@
import regeneratorDefine from "./regeneratorDefine.js";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Why is this deleted?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in Babel 7, and we didn't remove it before.

Copy link
Copy Markdown
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this PR been landed to Babel 8? If not could you prepare a new PR for Babel 8?

@liuxingbaoyu
Copy link
Copy Markdown
Member Author

Has this PR been landed to Babel 8? If not could you prepare a new PR for Babel 8?

Not yet, but I will.

@nicolo-ribaudo nicolo-ribaudo merged commit 68e1577 into babel:7.x Jan 16, 2026
65 checks passed
@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 Apr 18, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.