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: use const instead of enums to min bundle size #192

Merged

Conversation

davidlj95
Copy link
Owner

@davidlj95 davidlj95 commented Jan 17, 2024

Typescript enums are transformed into JS functions when compiling. Those create an object that can't be tree-shaken given it may be accessed dynamically. So using consts to ensure only the used enum props end up in the bundle

Indeed, Typescript enums may not be tree shaken even as a whole: microsoft/TypeScript#27604

Saving bytes as part of #112

Copy link
Owner Author

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

@davidlj95 davidlj95 mentioned this pull request Jan 17, 2024
Copy link

📦 Bundle size (Angular v15)

Git ref: 0da72c7

Module file Size Base size Difference
ngx-meta-core.mjs 3430 bytes (3.4KiB) 3430 bytes (3.4KiB) No change
ngx-meta-json-ld.mjs 402 bytes (402B) 402 bytes (402B) No change
ngx-meta-open-graph-profile.mjs 428 bytes (428B) 501 bytes (501B) -14.57%: -73 bytes (-73B)
ngx-meta-open-graph.mjs 833 bytes (833B) 1182 bytes (1.2KiB) -29.52%: -349 bytes (-349B)
ngx-meta-routing.mjs 897 bytes (897B) 897 bytes (897B) No change
ngx-meta-standard.mjs 940 bytes (940B) 940 bytes (940B) No change
ngx-meta-twitter-card.mjs 675 bytes (675B) 789 bytes (789B) -14.44%: -114 bytes (-114B)
Total 7605 bytes (7.5KiB) 8141 bytes (8.0KiB) -6.58%: -536 bytes (-536B)

Copy link

📦 Bundle size (Angular v16)

Git ref: 0da72c7

Module file Size Base size Difference
ngx-meta-core.mjs 3420 bytes (3.4KiB) 3420 bytes (3.4KiB) No change
ngx-meta-json-ld.mjs 402 bytes (402B) 402 bytes (402B) No change
ngx-meta-open-graph-profile.mjs 428 bytes (428B) 492 bytes (492B) -13.00%: -64 bytes (-64B)
ngx-meta-open-graph.mjs 833 bytes (833B) 1173 bytes (1.2KiB) -28.98%: -340 bytes (-340B)
ngx-meta-routing.mjs 897 bytes (897B) 897 bytes (897B) No change
ngx-meta-standard.mjs 940 bytes (940B) 940 bytes (940B) No change
ngx-meta-twitter-card.mjs 675 bytes (675B) 780 bytes (780B) -13.46%: -105 bytes (-105B)
Total 7595 bytes (7.5KiB) 8104 bytes (8.0KiB) -6.28%: -509 bytes (-509B)

Copy link

📦 Bundle size (Angular v17)

Git ref: 0da72c7

Module file Size Base size Difference
ngx-meta-core.mjs 3163 bytes (3.1KiB) 3163 bytes (3.1KiB) No change
ngx-meta-json-ld.mjs 236 bytes (236B) 236 bytes (236B) No change
ngx-meta-open-graph-profile.mjs 302 bytes (302B) 355 bytes (355B) -14.92%: -53 bytes (-53B)
ngx-meta-open-graph.mjs 670 bytes (670B) 1009 bytes (1009B) -33.59%: -339 bytes (-339B)
ngx-meta-routing.mjs 725 bytes (725B) 725 bytes (725B) No change
ngx-meta-standard.mjs 829 bytes (829B) 829 bytes (829B) No change
ngx-meta-twitter-card.mjs 515 bytes (515B) 615 bytes (615B) -16.26%: -100 bytes (-100B)
Total 6440 bytes (6.3KiB) 6932 bytes (6.8KiB) -7.09%: -492 bytes (-492B)

@davidlj95 davidlj95 merged commit a3a7679 into main Jan 17, 2024
12 checks passed
@davidlj95 davidlj95 deleted the stacked/perf-use-const-instead-of-enums-to-min-bundle-size branch January 17, 2024 12:31
Copy link

🎉 This PR is included in version 1.0.0-alpha.30 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

1 participant