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
tree-shake node bundle #1187
tree-shake node bundle #1187
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1187 +/- ##
==========================================
+ Coverage 93.71% 93.73% +0.02%
==========================================
Files 43 43
Lines 4023 4023
==========================================
+ Hits 3770 3771 +1
+ Misses 253 252 -1
Continue to review full report at Codecov.
|
Wow, good finding! I think this is premature optimization now. |
I totally agree. But I think the difference will never be significantly greater. So we might as well do it now and scrape off a few kb and a few milliseconds for the startup, anyway we have nothing to lose IMO. |
What part of the code is removed by the tree shaking? |
If I would guess. Everything under |
index-fetch.js
Outdated
let fetchImpl = null | ||
module.exports.fetch = async function fetch (resource, init) { | ||
if (!fetchImpl) { | ||
fetchImpl = require('./lib/fetch') | ||
} | ||
return fetchImpl.call(globalDispatcher, resource, init) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to lazy-load fetchImpl
?
Also, the small change I did in 3e267ec#diff-e727e4bdf3657fd1d798edcd6b099d6e092f8573cba266154583a746bba0f346 should be ported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
However I think we'll soon have to ship full undici to core (for the mocking capabilities).
* tree-shake node bundle * Update index-fetch.js Co-authored-by: Robert Nagy <ronagy@icloud.com>
* tree-shake node bundle * Update index-fetch.js Co-authored-by: Robert Nagy <ronagy@icloud.com>
* tree-shake node bundle * Update index-fetch.js Co-authored-by: Robert Nagy <ronagy@icloud.com>
Since Node.js only exposes these, we can make tree-sharking more efficient by exporting only what Node.js exposes. This currently saves about 54kb (381kb vs 327.4kb).
I don't know if it's worth it, but we have nothing to lose.
cc @targos