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 native fetch for node >= 18 to reduce %40 of bundle size #1724

Merged
merged 2 commits into from
Sep 13, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Sep 13, 2023

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Node.js 16 is EOL and by disabling the polyfill from node-fetch-native package, we can save almost %41 of the default bundle size!

This PR smartly enables experimental.nodeFetchCompact when Node.js 16 is being used with a warning to guide about an upgrade.

Output results

Node.js (current)
Ξ£ Total size: 268 kB (69.9 kB gzip)

Node.js (native fetch)
Ξ£ Total size: 158 kB (38.8 kB gzip)

We were also wrongly bundling polyfill for Bun which is not needed and it even saves more on bun (because of crypto export conditions mainly)

Bun (current)
Ξ£ Total size: 255 kB (66.7 kB gzip)

Bun (native fetch)
Ξ£ Total size: 146 kB (35.9 kB gzip)

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pi0 pi0 changed the title perf: use native fetch for node >= 18 to reduce %40 of bundle size perf: use native fetch for node >= 18 to reduce %40 of bundle size Sep 13, 2023
@pi0 pi0 assigned danielroe and unassigned danielroe Sep 13, 2023
@pi0 pi0 requested a review from danielroe September 13, 2023 16:18
@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Merging #1724 (cc73b02) into main (08f0152) will increase coverage by 0.00%.
The diff coverage is 83.33%.

@@           Coverage Diff           @@
##             main    #1724   +/-   ##
=======================================
  Coverage   77.27%   77.27%           
=======================================
  Files          75       75           
  Lines        7893     7911   +18     
  Branches      806      806           
=======================================
+ Hits         6099     6113   +14     
- Misses       1792     1796    +4     
  Partials        2        2           
Files Changed Coverage Ξ”
src/options.ts 96.30% <80.00%> (-0.70%) ⬇️
src/types/nitro.ts 100.00% <100.00%> (ΓΈ)

@pi0 pi0 merged commit 058bacf into main Sep 13, 2023
9 checks passed
@pi0 pi0 deleted the perf/node-fetch branch September 13, 2023 16:56
@pi0 pi0 mentioned this pull request Oct 5, 2023
@danielroe danielroe mentioned this pull request Oct 19, 2023
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