Skip to content

Code refactoring#5351

Merged
crocodile-dentist merged 9 commits into
mw/mux-single-peer-performancefrom
coot/mw/mux-single-peer-performance
Apr 13, 2026
Merged

Code refactoring#5351
crocodile-dentist merged 9 commits into
mw/mux-single-peer-performancefrom
coot/mw/mux-single-peer-performance

Conversation

@coot

@coot coot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Description

A series of refactoring patches in order to make the burst engine more readable
/ maintainable.

Related to #5322.

Checklist

Quality

  • Commit sequence makes sense and have useful messages, see ref.
  • New tests are added and existing tests are updated.
  • Self-reviewed the PR.

Maintenance

  • Linked an issue or added the PR to the current sprint of ouroboros-network project.
  • Added labels.
  • Updated changelog files.
  • The documentation has been properly updated, see ref.

@coot coot requested a review from a team as a code owner April 3, 2026 15:02
@github-project-automation github-project-automation Bot moved this to In Progress in Ouroboros Network Apr 3, 2026
@coot coot added the mux issues related to network-mux label Apr 3, 2026
@coot coot force-pushed the coot/mw/mux-single-peer-performance branch from 5cb25f2 to b4fd323 Compare April 3, 2026 15:43
@coot coot requested a review from Copilot April 3, 2026 17:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Refactors the mux egress burst batching logic to improve readability/maintainability by introducing clearer intermediate types and extracting token/SDU sizing logic into named helpers, while preserving the overall scheduling approach (weighted queues, batching, optional bursting).

Changes:

  • Introduces TokenSize, NextSDUSize, CanBurst, and SDUWithWantonState to make burst state and sizing decisions explicit.
  • Reworks buildBatch into a structured loop (burstLoop) with extracted helpers (computeSDUSize, consumedTokens, nextSDUSizeToSDUSize).
  • Updates processSingleWanton to return SDUWithWantonState instead of Either, and updates call sites accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread network-mux/src/Network/Mux/Egress.hs Outdated
Comment thread network-mux/src/Network/Mux/Egress.hs Outdated
Comment thread network-mux/src/Network/Mux/Egress.hs Outdated
Comment thread network-mux/src/Network/Mux/Egress.hs Outdated
Comment thread network-mux/src/Network/Mux/Egress.hs Outdated
case goAgain of
ContinueBurst | weight > 1 -> do
let egressQueues' = (pred weight, queue) : rest
go batch' egressQueues' StopBurst

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

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

This refactor materially changes the burst batching logic (token sizing, loop termination, and requeueing), but the existing test suite appears not to exercise burst mode (MiniProtocolLimits.burst = Nothing in network-mux/test/Test/Mux.hs). Adding at least one property/unit test that enables burst = Just ProtocolBurst{..} and asserts fairness/no starvation and token-bound sizing would help prevent regressions.

Suggested change
go batch' egressQueues' StopBurst
go batch' egressQueues' StopBurst
ContinueBurst -> do
let egressQueues' = rest <> [(1, queue)]
go batch' egressQueues' StopBurst

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@crocodile-dentist I'll keep it open, as it's relevant in the original #5322.

@coot coot force-pushed the coot/mw/mux-single-peer-performance branch 3 times, most recently from 59ee2a7 to 90c92ec Compare April 8, 2026 09:34
coot added 9 commits April 8, 2026 12:42
* added type signatures
* change argument order of `processSingleWanton`
* added `SDUWithWantonState`
* added bangs to all `go` definitions
Added dedicated API:
* `NextSDUSize`, `nextSDUSizeToSDUSize`
* `TokenSize` (type alias), `consumedTokens`
An explicit loop is easier to follow.  We also avoid calling `error
"impossible"`.
Replaced a custom `allM` with `foldMap All . traverse`.  In the future
we can fuse `foldMap` with `traverse`.
Move constants to top level bindings:
* `maxSDUsPerBatch`
* `burstMinSdu`
Replaced `Bool` with:
* `CanBatch` - can we batch more SDUs from different mini-protocols.
* `CanBurst` - can we burst more SDUs from a single mini-protocol.
Use an explicit loop in `muxer`, as a result `transformers` dependency
is gone.
Refactor `muxerLoop`

It's easier to read `[(EgressQueue m, [(Word8, Egress m)])]`, than the
other way around, since then it's the `EgressQueue` we read and its tail
much like `x : xs`.  This also avoids using `traverse` over tuple which
is a bit surprising.
Use DuplicateRecordFields for:
* `Wanton`
* `TranslocationServiceRequest`
* `ProtocolBurst`

These are all internal data types, so we won't force it on `network-mux`
user.
@coot coot force-pushed the coot/mw/mux-single-peer-performance branch from 90c92ec to 20e116a Compare April 8, 2026 10:43

@crocodile-dentist crocodile-dentist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@crocodile-dentist crocodile-dentist merged commit 9714b64 into mw/mux-single-peer-performance Apr 13, 2026
8 of 18 checks passed
@crocodile-dentist crocodile-dentist deleted the coot/mw/mux-single-peer-performance branch April 13, 2026 07:16
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Ouroboros Network Apr 13, 2026
@coot coot added the leios Issues / PRs related to Leios label Apr 14, 2026
@coot coot self-assigned this Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

leios Issues / PRs related to Leios mux issues related to network-mux

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants