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

quic: start adding in the internal quic js api #53256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Jun 2, 2024

While the external API for QUIC is expected to be the WebTransport API primarily, this provides the
internal API for QUIC that aligns with the native C++ QUIC components. This is the first of several PRs that will fill out this part of the implementation. The goal of doing this incrementally is to make things easier to review by doing it in smaller chunks

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jun 2, 2024
@jasnell jasnell added the quic Issues and PRs related to the QUIC implementation / HTTP/3. label Jun 2, 2024
@jasnell jasnell requested review from Qard and anonrig June 2, 2024 03:35
@jasnell jasnell force-pushed the quic-part-13 branch 2 times, most recently from 1babee6 to 9f2f600 Compare June 2, 2024 04:03
@jasnell jasnell requested a review from mcollina June 2, 2024 04:04
@jasnell jasnell requested a review from tniessen June 2, 2024 14:30
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
@targos targos added dont-land-on-v18.x PRs that should not land on the v18.x-staging branch and should not be released in v18.x. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. labels Jun 2, 2024
@jasnell jasnell force-pushed the quic-part-13 branch 8 times, most recently from d4ea9c3 to f245d2c Compare June 2, 2024 22:14
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
lib/internal/quic/quic.js Show resolved Hide resolved
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
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.

Unless a massive improvement is planned on WebStream, I would recommend not using them in this lower level. They are 1 order of magnitude slower than Node streams. Using them here would limit the applicability of our Quic implementation.

Just using functions and callbacks might even be faster.

@splitice
Copy link

splitice commented Jun 7, 2024

Really interesting @jasnell .

Just a reminder we have continued to apply fixes to your original attempt many of which probably still apply today (latest branch: https://github.com/HalleyAssist/node/commits/test_quic16/ - not everything in this branch is relevant). Some fixes could probably done better with more drastic changes, however they all represent observed leaks, infinite loops or crashes observed in our staging and pilot environments.

Including yesterday a fix for blocking streams creating an infinite loop in SendPendingData (which can be tested for with rx packet loss simulation). When you do get a JS api I'll try and contribute some of these directly.

Comment on lines 1288 to 1333
instance[kStats] = createStreamStats(handle.stats);
instance[kState] = createStreamState(handle.state);
Copy link
Member

Choose a reason for hiding this comment

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

Makes me a bit nervous that these names are a single character apart. High chance of typos in future maintenance.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not ignoring this comment, just plan to address it in a subsequent iteration

@jasnell jasnell force-pushed the quic-part-13 branch 3 times, most recently from a8066cd to 0253d2c Compare July 6, 2024 21:14
@jasnell jasnell requested review from mcollina, Qard and anonrig July 6, 2024 21:14
@jasnell
Copy link
Member Author

jasnell commented Jul 6, 2024

Updated the implementation fairly significantly here.

  1. Endpoint,Session, and Stream are no longer EventTarget subclasses. Instead, the constructor for Endpoint takes an object will callbacks that will be called. This preserves the idea that these are low-level APIs meant to be wrapped by other APIs to expose to users. The fact that these aren't EventTargets and Event objects aren't used should yield a fairly significant performance boost in the underlying bits.
  2. The constructors can be called directly. Since these are meant to be internal APIs there's not much harm in exposing those
  3. Uses more primordials consistently. I know there's some effort to remove primordials but as an internal API it makes sense here.
  4. Removing the use of ReadableStream/WritableStream at this level. These will be replaced with lower-level APIs and callbacks in the next step.
lib/internal/quic/quic.js Show resolved Hide resolved
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
lib/internal/quic/quic.js Outdated Show resolved Hide resolved
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Jul 7, 2024

@jasnell jasnell force-pushed the quic-part-13 branch 3 times, most recently from 43b9dbe to e456620 Compare July 7, 2024 22:19
@jasnell
Copy link
Member Author

jasnell commented Jul 7, 2024

This is generally ready to go except for the "Coverage" github CI tests. Working on increasing the test coverage now to the minimum that'll pass.

@jasnell jasnell force-pushed the quic-part-13 branch 4 times, most recently from aec7701 to 9dc124d Compare July 8, 2024 02:49
While the external API for QUIC is expected to be
the WebTransport API primarily, this provides the
internal API for QUIC that aligns with the native
C++ QUIC components.
}
}

class Stream {
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend we call this QuicInternalStream, otherwise this will quickly get confusing

*
* If a string is given it will be encoded as UTF-8.
*
* If an ArrayBufferView is given, the view will be copied.
Copy link
Member

Choose a reason for hiding this comment

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

The copy here would be problematic for perf reasons. Is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

This will likely be changed to detach the underlying ArrayBuffer instead of copy. The issue is that we do not want the buffer to be mutated while it is pending to be sent.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a TODO so we don't forget?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. dont-land-on-v18.x PRs that should not land on the v18.x-staging branch and should not be released in v18.x. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. quic Issues and PRs related to the QUIC implementation / HTTP/3.
8 participants