Skip to content

Shrink jsx helper size - #18325

Merged
nicolo-ribaudo merged 2 commits into
babel:mainfrom
JLHwung:shrink-jsx-helper-size
Oct 28, 2026
Merged

nicolo-ribaudo merged 2 commits into
babel:mainfrom
JLHwung:shrink-jsx-helper-size

Conversation

@JLHwung

@JLHwung JLHwung commented Oct 8, 2026

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? No
License MIT

In this PR we shrink the jsx helper size. The goal is to do it without behaviour changes and performance regression. Note that the argument loop could have been replaced by [].slice.call, but doing so yields 75% more running time than the current version.

@JLHwung JLHwung added the PR: Output optimization 🔬 A type of pull request used for our changelog categories label Oct 8, 2026
@babel-bot

babel-bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

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

@pkg-pr-new

pkg-pr-new Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: 0a70520

): ReactElement {
if (!REACT_ELEMENT_TYPE) {
REACT_ELEMENT_TYPE =
var elementType =

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.

We don't need this intermediate variable; it makes it look like we get smaller code just because we don't minify top-level names. I opened #18397 for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I will revisit this PR once #18397 has been merged and see if I can still shrink the size a bit.

@JLHwung
JLHwung force-pushed the shrink-jsx-helper-size branch from 326657f to 0a70520 Compare October 27, 2026 19:23
@JLHwung

JLHwung commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

I have rebased this PR, the new changes are still smaller than the current build, though the gain is very marginal (1 byte less after gzip).

Comment on lines +57 to +60
childArray = new Array(childrenLength);
for (var i = 0; i < childrenLength; i++) {
childArray[i] = arguments[i + 3];
}

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.

I’m not sure if .push is significantly slower, but it should help reduce the file size.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I prompted LLM to test on Node.js 6 and confirm that crankshaft can optimize indexed access and push, but not [].slice.call on arguments, I will update to the push approach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, if we use .push here, the @babel/runtime-corejs3 will pull _pushInstanceProperty(a).call(a, arguments[i + 3]) here, for the time being I will leave it as-is.

@nicolo-ribaudo
nicolo-ribaudo merged commit 8fc6a9c into babel:main Oct 28, 2026
57 of 58 checks passed
@nicolo-ribaudo
nicolo-ribaudo deleted the shrink-jsx-helper-size branch October 28, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Output optimization 🔬 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