Repository navigation
ProtocolRawMsg: const accessors and takeBuffer(); takeable buffers for encoded messages - #31
Merged
Merged
Conversation
So a message can be read in place in a queue (ThreadSafeQueue::peekWith passes it as const) - BLE sends a large message in pieces and copied the whole message for each piece. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CommsChannelMsg::setBufTakeable()/isBufTakeable(): set by a protocol codec on a message it made to send and doesn't use afterwards, so the channel sending it may move the buffer out rather than copy it. RICSerial sets it on its encoded message. A message passed on as it is (RICJSON, RICFrame) may be sent again - e.g. on each channel for MSG_CHANNEL_ID_ALL - so its buffer isn't takeable. ProtocolRawMsg::takeBuffer() takes a buffer's contents without copying. BLE queues the message this way, which saves a copy of each camera frame published (about 2 ms for a 10 KB frame on an ESP32-S3 with PSRAM). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets a channel queue an outbound message without copying it. Needed by robdobsn/RaftSysMods#12, so merge this first.
ProtocolRawMsg::getBuf()/getBufLen()are const, so a queued message can be read in place withThreadSafeQueue::peekWith(). BLE sent each large message in MTU-sized pieces and copied the whole message out of the queue for every piece (about 1.6 MB of copying for a 28 KB camera frame).CommsChannelMsg::setBufTakeable()/isBufTakeable(): a protocol codec marks a message it made to send and doesn't use afterwards, so the channel may move its buffer out instead of copying it.ProtocolRICSerialmarks its encoded message. Messages passed on as they are (ProtocolRICJSON,ProtocolRICFrame) aren't marked, as the same message may be sent again (e.g. on each channel forMSG_CHANNEL_ID_ALL).ProtocolRawMsg::takeBuffer()takes a buffer's contents without copying.No change for existing callers: nothing takes a buffer unless it checks
isBufTakeable().Tested with RaftSysMods#12 on an ESP32-S3 plant growth board, live camera frames (about 10 KB) over BLE: longest publish 5.5 ms (7.5 ms with the copy), longest loop about 7 ms.
🤖 Generated with Claude Code