use ref object for large events to avoid expensive deep copies

This commit is contained in:
Ivan FB 2026-05-29 11:30:24 +02:00
parent ad0fe71bbf
commit 9976fe3d07
No known key found for this signature in database
GPG Key ID: DF0C67A04C543270
2 changed files with 4 additions and 4 deletions

View File

@ -29,7 +29,7 @@ EventBroker:
##
## `channelId` lets listeners filter to their own channel, since all
## reliable channels share the underlying Waku node's broker context.
type ReadyToSendEvent* = object
type ReadyToSendEvent* = ref object
channelId*: SdsChannelID
msgs*: seq[seq[byte]]

View File

@ -166,7 +166,7 @@ proc onMessageError(self: ReliableChannel, messagingReqId: RequestId) =
self.pruneCompletedChannelReqs()
proc onReadyToSend(
self: ReliableChannel, msgs: sink seq[seq[byte]]
self: ReliableChannel, readyToSendEvent: ReadyToSendEvent
) {.async: (raises: []).} =
## Tail of the outgoing pipeline. Invoked from the `ReadyToSendEvent`
## listener once `rate_limit_manager` releases a batch of opaque
@ -174,7 +174,7 @@ proc onReadyToSend(
##
## ... -> rate_limit_manager -> [encryption] -> dispatch
var idx = 0
for m in msgs:
for m in readyToSendEvent.msgs:
## The first `AwaitingRateLimit` entry in push order is the one
## this `m` belongs to: `send()` adds one entry per segment, and
## `rate_limit_manager` re-emits them in the same FIFO order, so
@ -395,7 +395,7 @@ proc new*(
chn.brokerCtx,
proc(evt: ReadyToSendEvent): Future[void] {.async: (raises: []).} =
if evt.channelId == chn.channelId:
await chn.onReadyToSend(evt.msgs)
await chn.onReadyToSend(evt)
,
)