Repository navigation
core: optimize away dynamic_cast, avoid allocations - #424
Merged
Merged
Conversation
MariusBgm
marked this pull request as ready for review
September 16, 2026 09:11
MariusBgm
force-pushed
the
dev/zero_copy_opt
branch
from
September 25, 2026 06:11
a59dd7d to
2f8b749
Compare
snps-fricke
approved these changes
Oct 8, 2026
snps-fricke
left a comment
Collaborator
There was a problem hiding this comment.
Really nice work, the fan-out design is clean and very well tested. If anything, I'd reiterate on the lifetime of receive buffers and see if that path can be simplified.
Signed-off-by: Marius Börschig <Marius.Boerschig@vector.com>
Reusable receive descriptor — VAsioConnection now assigns into a member ServiceDescriptor instead of constructing a fresh one per received message. std::map assignment reuses nodes and std::string assignment reuses buffers, so the supplemental-data allocations disappear. Safe because only the io thread reaches it and dispatch is synchronous. Pooled serialization buffer — a thread-local free list in MessageBuffer. The writing constructor takes a buffer from it; MakeSendItem hands it back once a small message has been copied inline. Thread-local means no synchronization, and a buffer acquired on one thread and recycled on another just migrates between lists. Pooled receive blob — AcquireReceiveBlob reuses a blob only when its use_count() == 1, which is precisely the condition that no deserialized payload still aliases it. Self-correcting: if a payload somehow outlives dispatch, that entry is skipped and a fresh blob is allocated. Both pools are capped (32 buffers / 8 blobs, 64 KB each) so large messages don't cause hoarding. Signed-off-by: Marius Börschig <Marius.Boerschig@vector.com>
Two independent findings from profiling the small message path with callgrind and DHAT, 400,000 messages of 10 bytes between two participants. asio copies a buffer sequence into the async operation, which DHAT attributed as one allocation of 16 bytes per message. A single buffer is stored in the operation by value instead, so AsyncWriteSome and AsyncReadSome now take that path when the sequence holds exactly one buffer. That is the common case: a small message is written as one contiguous buffer, and the receive ring only needs a second buffer when its free region wraps. AcquireReceiveBlob resized a pooled blob to the exact message size, value initializing bytes that RingBuffer::Read overwrites immediately afterwards. Pooled blobs now only grow and stay at their high water size, and the caller reads and views exactly the message's bytes. This part is a regression from the commit that introduced the pool. Signed-off-by: Marius Börschig <Marius.Boerschig@vector.com>
- replace thread_local receive blob pool with ReceiveBlobPool owned by VAsioConnection - add Experimental.UseReceiveBufferPool (default true) to disable pooling for diagnosis - reuse best-fitting blob, cap slack at 4 KiB, acquire fence after use_count check - add VAsioPeer tests: inline/owned/shared send items, partial writes, aggregation, receive paths - add ReceiveBlobPool, VAsioProxyPeer and serdes aliasing / RPC wire format tests - add fan-out ITests: pubsub 1:3 (aggregation, pool off), RPC 1:2, large Ethernet frames, mixed direct/proxied subscribers - use non-uniform payloads in pubsub ITest harness - document UseReceiveBufferPool Signed-off-by: Marius Börschig <Marius.Boerschig@vector.com>
Signed-off-by: Marius Börschig <Marius.Boerschig@vector.com>
Signed-off-by: Marius Börschig <Marius.Boerschig@vector.com>
constructor, which the receive blob pool relied on. - Add an explicit constructor viewing a whole shared vector without copying. VAsioPeer narrows it to the message with Subspan(), which stays the only way to narrow a view. - Port the tests that still used MakeSharedSpan. Signed-off-by: Marius Börschig <marius.boerschig@vector.com>
- Dispatch is synchronous and nothing keeps a received payload past its handler, so at most one blob is in use at a time. - The use_count guard stays: a retained payload keeps its blob, and the pool continues with a fresh one instead of overwriting it. - A retained payload now pins up to MaxBlobSize (64 KiB), since the slack bound is gone. Signed-off-by: Marius Börschig <marius.boerschig@vector.com>
MariusBgm
force-pushed
the
dev/zero_copy_opt
branch
from
November 2, 2026 11:48
20bedb2 to
b3e5b13
Compare
snps-fricke
reviewed
Nov 2, 2026
- Nothing on the receive path keeps a SerializedMessage past the call; lvalue references state that in the signatures. - Not const&: the const Deserialize() copies the buffer, which for vector-backed messages (e.g. proxied ones) copies the payload. Signed-off-by: Marius Börschig <marius.boerschig@vector.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.
Three profiling-driven optimizations on top of #423. No API, ABI or wire format change.
dynamic_castcalls: one was a plain upcast, the other is now resolved once at receiver registration. Takes the RTTIstrcmpwith it.ServiceDescriptorper message; pool the serialization buffer and the receive blob (thread local, no locking).