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

tree-shake node bundle #1187

Merged
merged 3 commits into from Apr 22, 2022
Merged

tree-shake node bundle #1187

merged 3 commits into from Apr 22, 2022

Conversation

Mesteery
Copy link
Member

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

@codecov-commenter
Copy link

codecov-commenter commented Jan 30, 2022

Codecov Report

Merging #1187 (5e59547) into main (72c2a51) will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
lib/fetch/request.js 82.15% <0.00%> (+0.41%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72c2a51...5e59547. Read the comment docs.

@mcollina
Copy link
Member

Wow, good finding! I think this is premature optimization now.

@Mesteery
Copy link
Member Author

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.

@targos
Copy link
Member

targos commented Jan 31, 2022

What part of the code is removed by the tree shaking?

@ronag
Copy link
Member

ronag commented Jan 31, 2022

If I would guess. Everything under lib/api.

index-fetch.js Outdated
Comment on lines 7 to 13
let fetchImpl = null
module.exports.fetch = async function fetch (resource, init) {
if (!fetchImpl) {
fetchImpl = require('./lib/fetch')
}
return fetchImpl.call(globalDispatcher, resource, init)
}
Copy link
Member

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.

@ronag ronag requested a review from mcollina April 22, 2022 08:55
Copy link
Member

@mcollina mcollina left a 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).

@ronag ronag merged commit 950a78c into nodejs:main Apr 22, 2022
KhafraDev pushed a commit to KhafraDev/undici that referenced this pull request Jun 23, 2022
* tree-shake node bundle

* Update index-fetch.js

Co-authored-by: Robert Nagy <ronagy@icloud.com>
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
* tree-shake node bundle

* Update index-fetch.js

Co-authored-by: Robert Nagy <ronagy@icloud.com>
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* tree-shake node bundle

* Update index-fetch.js

Co-authored-by: Robert Nagy <ronagy@icloud.com>
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.

None yet

5 participants