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

chore: Split Fetch code #2366

Closed
wants to merge 2 commits into from
Closed

Conversation

kibertoad
Copy link
Contributor

@kibertoad kibertoad commented Oct 22, 2023

This relates to Undici code structure

Rationale

I've started looking into https://twitter.com/bengl/status/1715958172400210065 to identify quick perf wins for the hot path, but quickly hit a roadblock, due to "monolithic block of code" style of code, that is hard to penetrate for an outsider. Since inline function declarations in the original code served as a way to pass closure variables, I've reimplemented this part of the code as a class, which exists precisely for carrying this kind of a context.

Changes

This is pretty much the original code, just broken down into more manageable pieces.

Features

N/A

Bug Fixes

N/A

Breaking Changes and Deprecations

Shouldn't be a breaking change

Status

@kibertoad
Copy link
Contributor Author

@mcollina @KhafraDev Could you please take a look if this is something that makes sense within the undici codebase? Tests are still failing, but I don't want to invest much effort into something that will be rejected anyway.

}
}

module.exports = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to split this into three separate files initially, but unfortunately that doesn't fly; as currently implemented, there is a circular reference across these three functions, so they can't be split at all. For me that sounds like a code smell, but this is a larger problem than what could be solved in this PR.

@codecov-commenter
Copy link

codecov-commenter commented Oct 22, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (e39a632) 85.54% compared to head (ae7c9a6) 92.23%.
Report is 61 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2366      +/-   ##
==========================================
+ Coverage   85.54%   92.23%   +6.68%     
==========================================
  Files          76       41      -35     
  Lines        6858     3258    -3600     
==========================================
- Hits         5867     3005    -2862     
+ Misses        991      253     -738     
Files Coverage Δ
lib/api/readable.js 83.07% <100.00%> (-8.47%) ⬇️
lib/core/connect.js 80.00% <100.00%> (-1.25%) ⬇️
lib/core/request.js 88.09% <100.00%> (+1.01%) ⬆️
lib/pool.js 100.00% <100.00%> (ø)
lib/client.js 93.18% <93.33%> (+0.06%) ⬆️
lib/api/api-stream.js 98.11% <60.00%> (-1.89%) ⬇️
lib/core/util.js 82.63% <85.71%> (-13.16%) ⬇️

... and 38 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@KhafraDev
Copy link
Member

If you have the fetch spec open, having the entirety of fetch in its own file makes maintaining it much easier. I'd also like to mention that some people have tried going through fetch for "easy" perf gains and there probably aren't that many that would be accepted.

@kibertoad
Copy link
Contributor Author

fair point, I'll just close this then. This PR is making me feel miserable anyway :-D

@kibertoad kibertoad closed this Oct 22, 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.

3 participants