-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
[WIP] lib: merge onread handlers for http2 streams & net.Socket #20993
Conversation
@@ -513,6 +514,12 @@ Object.defineProperty(Socket.prototype, 'bufferSize', { | |||
} | |||
}); | |||
|
|||
Object.defineProperty(Socket.prototype, kUpdateTimer, { | |||
get: function() { |
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.
We should probably avoid getters for hot paths like a socket read callback function.
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.
I wouldn’t expect it to make a big difference? I’d expect V8 to inline this – if benchmark runs come back okay, is this still an issue?
That being said, it might be nice to move over to using kUpdateTimer
in all cases.
@@ -81,8 +81,40 @@ function afterWriteDispatched(self, req, err, cb) { | |||
} | |||
} | |||
|
|||
function _onread(handle, stream, nread, buf) { | |||
stream[kUpdateTimer](); |
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.
Isn't this deviating from http2's original implementation? Previously for http2 this was only called inside the conditional below.
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.
I don’t think that’s an issue either, and arguably a bit more correct this way.
} | ||
|
||
// Last chunk was received. End the readable side. | ||
debug(`Http2Stream ${stream[kID]} [Http2Session ` + |
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.
This is missing in the new implementation
I'm not sure how feasible it is to do a proper job of merging these. HTTP2 has pretty different requirements here. The bits that are shared are actually quite minimal (basically the first |
function _onread(handle, stream, nread, buf) { | ||
stream[kUpdateTimer](); | ||
|
||
if (nread > 0 && !stream.destroyed) { |
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.
This is not the same as the previous http2 implementation, which executed the logic within this block when nread >= 0
, not just nread > 0
.
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.
I don’t think omitting 0-sized reads is an issue.
I agree, there seems to be subtle differences that would make merging difficult, especially efficiently. |
@@ -2122,6 +2102,7 @@ function afterOpen(session, options, headers, streamOptions, err, fd) { | |||
class ServerHttp2Stream extends Http2Stream { | |||
constructor(session, handle, id, options, headers) { | |||
super(session, options); | |||
handle.owner = this; |
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.
I think it might be better to attach [kOwner]
in net.js
(and later switching over to always using that symbol over there)
Generally, it would imo be a good idea to have a standardized way to access the JS wrapper object from a C++ handle, and handle[kOwner]
might be exactly that
@aks- Thanks for doing this! I’m sorry I didn’t reply sooner, feel free to @ me if you like. Could you rebase this against |
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.
I think having benchmark results would be good considering some of the changes being made here.
@ryzokuken Do you maybe have the time to look at this? |
@addaleax will take a look tonight, sure! |
Got an updated version in #22449 |
Refs: nodejs#20993 Co-authored-by: Anna Henningsen <anna@addaleax.net>
Done! |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes