Reduces allocation and memory copies for processing JSON messages#51
Merged
Conversation
Uses const char * pointers directly into the websocket payload instead of creating an intermediate string copy that gets passed around.
There was a problem hiding this comment.
Pull request overview
This PR changes the JSON message delivery path to avoid allocating/copying an intermediate std::string by passing a (char* data, size_t len) view directly into the connection’s WebSocket reassembly buffer, and parsing from that buffer in-place.
Changes:
- Update
on_json_message_cb(and related call sites) to take a pointer + length instead ofstd::string. - Update
SendspinConnection::dispatch_completed_message()to invoke the JSON callback directly on the reassembly buffer (nostd::stringconstruction). - Update
SendspinClient::process_json_message()to deserialize JSON from(data, len).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/host/client_connection.h | Updates documentation example for the new JSON callback signature. |
| src/connection.h | Updates JSON callback type + documentation and describes new dispatch behavior. |
| src/connection.cpp | Removes std::string copy during dispatch; passes buffer pointer/len to callback. |
| src/connection_manager.cpp | Propagates new callback signature to client JSON processing. |
| src/client.cpp | Parses JSON directly from the connection buffer via (data, len). |
| include/sendspin/client.h | Updates private client JSON processing signature and docs to match new buffer-based parsing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Uses
const charpointers directly into the websocket payload instead of creating an intermediate string copy that gets passed around.