From c1911b6e44795f16291d63620825fb13007d9437 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 2 Jul 2024 14:29:26 -0400 Subject: [PATCH] Comments on cross-thread allocation. --- src/net/proxy.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/net/proxy.cpp b/src/net/proxy.cpp index 81c11a05b..59f40f95d 100644 --- a/src/net/proxy.cpp +++ b/src/net/proxy.cpp @@ -254,6 +254,8 @@ void proxy::handle_read_heading(const code& ec, size_t) NOEXCEPT } // Handle errors and post message to subscribers. +// The head object is allocated on another thread and destroyed on this one. +// This introduces cross-thread allocation/deallocation, though size is small. void proxy::handle_read_payload(const code& ec, size_t LOG_ONLY(payload_size), const heading_ptr& head) NOEXCEPT { @@ -292,6 +294,10 @@ void proxy::handle_read_payload(const code& ec, size_t LOG_ONLY(payload_size), } // Notify subscribers of the new message. + // The message object is allocated on this thread and notify invokes + // subscribers on the same thread. This significantly reduces deallocation + // cost in constrast to allowing the object to destroyed on another thread. + // If object is passed to another thread destruction cost can be very high. const auto code = notify(head->id(), version(), payload_buffer_); if (code)