Skip to content

Commit

Permalink
Comments on cross-thread allocation.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Jul 2, 2024
1 parent 757095e commit c1911b6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/net/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c1911b6

Please sign in to comment.