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

[Decorators][Docs] Clarify that modern decorator usage will increase TypeScript project bundle size #3931

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chadsowald
Copy link

Clarified that using modern decorators will increase the output bundle size for TypeScript projects.

I ran into this on my project after upgrading from legacy decorators. I wanted to add this to the docs so others don't have to find out the hard way. Once ESNext is supported by major browsers, though, it will be great!

Clarified that using modern decorators will increase the output bundle size for TypeScript projects.
Copy link

changeset-bot bot commented Oct 2, 2024

⚠️ No Changeset found

Latest commit: 6b08279

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chadsowald chadsowald changed the title [Decorators] Clarify that modern decorator usage will increase TypeScript project bundle size [Decorators][Docs] Clarify that modern decorator usage will increase TypeScript project bundle size Oct 2, 2024
Copy link
Member

@mweststrate mweststrate left a comment

Choose a reason for hiding this comment

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

Would you mind quantifying the change, and where it comes from? How it is formulated is pretty clear whether a) it is 100 bytes or 100 KB, and b) whether this is a shared resource like polyfills or something else. Mind charing the difference in transpiled output?

@chadsowald
Copy link
Author

@mweststrate definitely! Here's some examples from the TypeScript Playground - rather than my specific project's code - that illustrates the tradeoff. Would you like me to include these details in the doc update too, or just here?

With experimentalDecorators on + ES2023

With experimentalDecorators off + ES2023

With experimentalDecorators off + ESNext

You can see that web projects following the migration guide to "modern decorators" would be hit by the diff between the first 2 links above. Then, whenever ESNext is released and enough browsers support modern decorators, then we'll all benefit from the size reduction in the 3rd link. At least, I think that's my understanding.

Does that seem about right?

It's hard to quantify the overall size impact as it depends on how much decorator use there is and how large the project is.

In my case, my project heavily uses mobx decorators and the move to modern decorators added ~40kb after compression! But is has many stores, observables, and more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants