Skip to content

Conversation

@shikokuchuo
Copy link
Member

Closes #219.

This PR allocates a nng_msg upfront and uses nng_msg_append() directly in all the internal encoding and serialization functions to avoid allocation of an intermediate object and memcpy - reducing peak memory usage.

Previously, we used a nano_buf struct (similar to base R's membuf). This held the serialized object before being appended in its entirety to an nng_msg. This would perform a memcpy() on the object - a real one, not one that would be optimized away by the compiler.

Note: we still retain the use of nano_buf in places such as stream sends which are not nng_msg based.

FYI @lionel-

Copy link
Member Author

@shikokuchuo shikokuchuo left a comment

Choose a reason for hiding this comment

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

Valgrind run comes in clean.

Copy link
Member Author

@shikokuchuo shikokuchuo left a comment

Choose a reason for hiding this comment

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

@shikokuchuo shikokuchuo merged commit cb088f3 into main Dec 3, 2025
31 checks passed
@shikokuchuo shikokuchuo deleted the msg branch December 3, 2025 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Append to nng_msg directly during serialization

2 participants