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

perf: Improve @babel/generator performance #16061

Merged
merged 3 commits into from Oct 26, 2023

Conversation

liuxingbaoyu
Copy link
Member

@liuxingbaoyu liuxingbaoyu commented Oct 25, 2023

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

Time consumption reduced by ~15%

PS F:\babel\benchmark\babel-generator\real-case> node .\jquery.mjs
current 1 jquery 3.6: 165 ops/sec ±0.61% (6.056ms)
current 4 jquery 3.6: 39.67 ops/sec ±0.98% (25ms)
current 16 jquery 3.6: 9.31 ops/sec ±3.4% (107ms)
current 64 jquery 3.6: 2.3 ops/sec ±1.37% (435ms)
baseline 1 jquery 3.6: 135 ops/sec ±0.71% (7.41ms)
baseline 4 jquery 3.6: 32.78 ops/sec ±2.38% (31ms)
baseline 16 jquery 3.6: 8.11 ops/sec ±0.7% (123ms)
baseline 64 jquery 3.6: 1.95 ops/sec ±1.05% (513ms)

@liuxingbaoyu liuxingbaoyu added pkg: generator PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories labels Oct 25, 2023
@babel-bot
Copy link
Collaborator

babel-bot commented Oct 25, 2023

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

Copy link
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.

Great!

packages/babel-generator/src/node/index.ts Outdated Show resolved Hide resolved

this._indentChar = format.indent.style.charCodeAt(0);
this._indentRepeat = format.indent.style.length;

this._inputMap = map?._inputMap;

this._buf = new Buffer(map, this._indentChar);
Copy link
Member

Choose a reason for hiding this comment

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

Could we already pass String.fromCharCode(this._indentChar) here, so that then we don't have to convert it multiple times inside Buffer?

liuxingbaoyu and others added 2 commits October 26, 2023 08:24
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Copy link
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.

Awesome.

@nicolo-ribaudo nicolo-ribaudo merged commit 888903e into babel:main Oct 26, 2023
48 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 Jan 30, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 30, 2024
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.

None yet

4 participants