Skip to content

Reduces allocation and memory copies for processing JSON messages#51

Merged
kahrendt merged 3 commits into
mainfrom
reduce-copies-with-json-messages
May 11, 2026
Merged

Reduces allocation and memory copies for processing JSON messages#51
kahrendt merged 3 commits into
mainfrom
reduce-copies-with-json-messages

Conversation

@kahrendt
Copy link
Copy Markdown
Contributor

@kahrendt kahrendt commented May 11, 2026

Uses const char pointers directly into the websocket payload instead of creating an intermediate string copy that gets passed around.

Uses const char * pointers directly into the websocket payload instead of creating an intermediate string copy that gets passed around.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 of std::string.
  • Update SendspinConnection::dispatch_completed_message() to invoke the JSON callback directly on the reassembly buffer (no std::string construction).
  • 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.

Comment thread src/connection.cpp Outdated
Comment thread src/connection.h Outdated
Comment thread include/sendspin/client.h Outdated
@kahrendt kahrendt enabled auto-merge (squash) May 11, 2026 18:23
@kahrendt kahrendt disabled auto-merge May 11, 2026 18:24
@kahrendt kahrendt enabled auto-merge (squash) May 11, 2026 18:24
@kahrendt kahrendt merged commit 5e66e64 into main May 11, 2026
4 checks passed
@kahrendt kahrendt deleted the reduce-copies-with-json-messages branch May 11, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants