Skip to content

feat(iroh): expose batch datagram send/recv APIs - #4383

Open
ifdario wants to merge 3 commits into
n0-computer:mainfrom
rayfish:perf/datagram-batching
Open

ifdario wants to merge 3 commits into
n0-computer:mainfrom
rayfish:perf/datagram-batching

Conversation

@ifdario

@ifdario ifdario commented Jul 1, 2026

Copy link
Copy Markdown

Description

Expose the new noq batch datagram APIs through iroh's Connection wrapper so downstream crates (e.g. rayfish) can amortize the per-datagram connection-mutex cost, which is the dominant overhead at high pps for a mesh VPN forwarding bursts of TUN packets.

  • Connection::send_datagrams / read_datagrams delegate to noq::Connection.
  • Re-export ReadDatagrams and SendMany through endpoint::quic and the public endpoint surface (required by the crate's unreachable_pub lint).

Depends on the noq PR that adds Connection::send_datagrams / read_datagrams and DatagramState::recv_many / Datagrams::send_many. This branch should not merge until that noq release is published and the [patch.crates-io] override (see below) is removed.

Breaking Changes

None. All additions are additive methods and types. Existing send_datagram / read_datagram / send_datagram_wait are unchanged.

Notes & open questions

  • This branch currently carries a [patch.crates-io] override in the workspace Cargo.toml pointing noq / noq-proto / noq-udp at a local fork (../noq) so iroh can see the new APIs during development. This MUST be removed before merge, which requires the noq batch-API PR to be merged and a new noq release published to crates.io first. Leaving the patch in would break CI for anyone without the local ../noq checkout.
  • The noq dependency version in iroh/Cargo.toml is not yet bumped; a follow-up commit will bump noq (and noq-proto / noq-udp) to the released version that contains the batch APIs, and remove the patch, in the same change.
  • No new tests in iroh itself. The underlying APIs are tested in noq; iroh's wrappers are thin passthroughs, so the existing iroh datagram tests continue to exercise the single-datagram path. Adding an iroh-level integration test for the batch passthrough is possible but deferred to avoid duplication.
  • No benchmark delta. iroh's internals do not use the batch APIs yet, so iroh's own performance is unchanged. The win is realized by downstream callers that batch (e.g. rayfish's TUN read loop). Measuring that is left to the downstream caller.

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant. (deferred, see Notes)
  • All breaking changes documented. (none)

Add thin passthroughs to the underlying noq batch APIs so downstream
crates (e.g. rayfish) can amortize the per-datagram connection-mutex
cost, which is the dominant overhead at high pps for a mesh VPN
forwarding bursts of TUN packets.

- Connection::send_datagrams / read_datagrams delegate to noq::Connection.
- Re-export ReadDatagrams and SendMany through endpoint::quic and the
  public endpoint surface (required by the crate's unreachable_pub lint).
- Add [patch.crates-io] pointing noq/noq-proto/noq-udp at the local fork
  (../noq) so iroh builds against the rayfish noq with the batch APIs.
  This is a workspace-local dev override; published iroh still resolves
  to noq 1.0.1 from crates.io.
Comment thread Cargo.toml Outdated
Comment on lines +45 to +48
[patch.crates-io]
noq = { path = "../noq/noq" }
noq-proto = { path = "../noq/noq-proto" }
noq-udp = { path = "../noq/noq-udp" }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs paths to be updated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll do it once we merge noq. Then we can upgrade to whatever version that one adds

@n0bot n0bot Bot added this to iroh Jul 1, 2026
@github-project-automation github-project-automation Bot moved this to 🚑 Needs Triage in iroh Jul 1, 2026
@ifdario

ifdario commented Jul 1, 2026

Copy link
Copy Markdown
Author

Related: n0-computer/noq#735

@ifdario ifdario changed the title perf(datagrams): expose batch send/recv APIs through iroh Connection WIP: perf(datagrams): expose batch send/recv APIs through iroh Connection Jul 1, 2026
@flub

flub commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks for taking care of this side as well! But let's move this back into draft until n0-computer/noq#735 is merged. Please re-open once that's been merged.

@flub
flub marked this pull request as draft July 1, 2026 14:06
ifdario added 2 commits July 11, 2026 11:19
Follow the noq rename to read_many_datagrams / send_many_datagrams and
the slice-based signatures.
ifdario added a commit to rayfish/rayfish that referenced this pull request Sep 1, 2026
Take inbound packets from a peer connection with read_many_datagrams, so a
burst is drained under one lock hold instead of a wake per packet, and hand
the lazy-dial backlog to send_many_datagrams in per-route runs.

The batch APIs come from noq via the rayfish forks (n0-computer/noq#735,
n0-computer/iroh#4383), so ray patches noq alongside iroh and netwatch. The
drop-newest policy is kept by tracking the bytes already staged in a run
against the connection's send buffer space.
@flub

flub commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Hey, this batch API is now released in noq. I think this can be updated and the PR opened? It looks very straight forward, so probably not much holding up this PR once it's open.

@flub
flub marked this pull request as ready for review September 11, 2026 17:17
Comment thread Cargo.toml
# a noq release carries them.
noq = { git = "https://github.com/rayfish/noq", branch = "perf/datagram-batching" }
noq-proto = { git = "https://github.com/rayfish/noq", branch = "perf/datagram-batching" }
noq-udp = { git = "https://github.com/rayfish/noq", branch = "perf/datagram-batching" }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The whole patch section should be able to be removed now

@flub flub changed the title WIP: perf(datagrams): expose batch send/recv APIs through iroh Connection feat(iroh): expose batch datagram send/recv APIs Sep 11, 2026
@flub

flub commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Could you update the description to the current state? That becomes the commit message once we merge. Also if you could change "breaking changes" into "api changes" and list the new APIs that would be great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🚑 Needs Triage

Development

Successfully merging this pull request may close these issues.

3 participants