Return-Path: X-Original-To: apmail-qpid-commits-archive@www.apache.org Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A64A0187B1 for ; Mon, 28 Sep 2015 18:09:28 +0000 (UTC) Received: (qmail 50896 invoked by uid 500); 28 Sep 2015 18:09:28 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 50762 invoked by uid 500); 28 Sep 2015 18:09:28 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 50657 invoked by uid 99); 28 Sep 2015 18:09:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Sep 2015 18:09:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 01D58E0509; Mon, 28 Sep 2015 18:09:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aconway@apache.org To: commits@qpid.apache.org Date: Mon, 28 Sep 2015 18:09:36 -0000 Message-Id: In-Reply-To: <6da54274bfd24239975b24dcba31706e@git.apache.org> References: <6da54274bfd24239975b24dcba31706e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [10/50] [abbrv] qpid-proton git commit: PROTON-998: [C++ binding] restore lost performance PROTON-998: [C++ binding] restore lost performance Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/05beb218 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/05beb218 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/05beb218 Branch: refs/heads/proton-go Commit: 05beb2183dc0c0232284f045007f8d3af2ed73e7 Parents: f17cc97 Author: Clifford Jansen Authored: Wed Sep 16 10:56:30 2015 -0700 Committer: Clifford Jansen Committed: Wed Sep 16 10:56:30 2015 -0700 ---------------------------------------------------------------------- proton-c/bindings/cpp/include/proton/messaging_event.hpp | 3 ++- proton-c/bindings/cpp/src/container_impl.cpp | 8 ++++++++ proton-c/bindings/cpp/src/contexts.hpp | 1 + proton-c/bindings/cpp/src/messaging_adapter.cpp | 11 ++++++++++- proton-c/bindings/cpp/src/messaging_event.cpp | 11 ++++++++--- 5 files changed, 29 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/05beb218/proton-c/bindings/cpp/include/proton/messaging_event.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/messaging_event.hpp b/proton-c/bindings/cpp/include/proton/messaging_event.hpp index af22b41..5553faf 100644 --- a/proton-c/bindings/cpp/include/proton/messaging_event.hpp +++ b/proton-c/bindings/cpp/include/proton/messaging_event.hpp @@ -23,6 +23,7 @@ */ #include "proton/proton_event.hpp" #include "proton/link.hpp" +#include "proton/message.hpp" namespace proton { @@ -98,7 +99,7 @@ class messaging_event : public proton_event friend class messaging_adapter; event_type type_; proton_event *parent_event_; - message_value message_; + class message *message_; messaging_event operator=(const messaging_event&); messaging_event(const messaging_event&); }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/05beb218/proton-c/bindings/cpp/src/container_impl.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/container_impl.cpp b/proton-c/bindings/cpp/src/container_impl.cpp index a13d961..ca864a7 100644 --- a/proton-c/bindings/cpp/src/container_impl.cpp +++ b/proton-c/bindings/cpp/src/container_impl.cpp @@ -51,6 +51,14 @@ struct handler_context { } static void cleanup(pn_handler_t*) {} + /* + * NOTE: this call, at the transition from C to C++ is possibly + * the biggest performance bottleneck. "Average" clients ignore + * 90% of these events. Current strategy is to create the + * messaging_event on the stack. For success, the messaging_event + * should be small and free of indirect malloc/free/new/delete. + */ + static void dispatch(pn_handler_t *c_handler, pn_event_t *c_event, pn_event_type_t type) { handler_context& hc(handler_context::get(c_handler)); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/05beb218/proton-c/bindings/cpp/src/contexts.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/contexts.hpp b/proton-c/bindings/cpp/src/contexts.hpp index 80e3d00..1a11259 100644 --- a/proton-c/bindings/cpp/src/contexts.hpp +++ b/proton-c/bindings/cpp/src/contexts.hpp @@ -47,6 +47,7 @@ struct connection_context : public counted { pn_unique_ptr handler; session* default_session; // Owned by connection class container_impl* container_impl; + class message_value event_message; // re-used by messaging_adapter for performance }; class container; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/05beb218/proton-c/bindings/cpp/src/messaging_adapter.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/messaging_adapter.cpp b/proton-c/bindings/cpp/src/messaging_adapter.cpp index 39d80b8..27dcc34 100644 --- a/proton-c/bindings/cpp/src/messaging_adapter.cpp +++ b/proton-c/bindings/cpp/src/messaging_adapter.cpp @@ -23,12 +23,14 @@ #include "proton/sender.hpp" #include "proton/error.hpp" #include "msg.hpp" +#include "contexts.hpp" #include "proton/link.h" #include "proton/handlers.h" #include "proton/delivery.h" #include "proton/connection.h" #include "proton/session.h" +#include "proton/message.h" namespace proton { messaging_adapter::messaging_adapter(messaging_handler &delegate_) : @@ -72,7 +74,14 @@ void messaging_adapter::on_delivery(event &e) { if (!pn_delivery_partial(dlv) && pn_delivery_readable(dlv)) { // generate on_message messaging_event mevent(messaging_event::MESSAGE, *pe); - mevent.message_.decode(*reinterpret_cast(lnk), *reinterpret_cast(dlv)); + pn_connection_t *pnc = pn_session_connection(pn_link_session(lnk)); + struct connection_context& ctx = connection_context::get(pnc); + // Reusable per-connection message. Avoid expensive heap malloc/free overhead. + // See PROTON-998 + class message &msg(ctx.event_message); + mevent.message_ = &msg; + + mevent.message_->decode(*reinterpret_cast(lnk), *reinterpret_cast(dlv)); if (pn_link_state(lnk) & PN_LOCAL_CLOSED) { if (auto_accept_) { pn_delivery_update(dlv, PN_RELEASED); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/05beb218/proton-c/bindings/cpp/src/messaging_event.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/messaging_event.cpp b/proton-c/bindings/cpp/src/messaging_event.cpp index ece1c4e..82f9159 100644 --- a/proton-c/bindings/cpp/src/messaging_event.cpp +++ b/proton-c/bindings/cpp/src/messaging_event.cpp @@ -33,14 +33,19 @@ #include "msg.hpp" #include "contexts.hpp" +/* + * Performance note: + * See comments for handler_context::dispatch() in container_impl.cpp. + */ + namespace proton { messaging_event::messaging_event(pn_event_t *ce, proton_event::event_type t, class container &c) : - proton_event(ce, t, c), type_(messaging_event::PROTON), parent_event_(0) + proton_event(ce, t, c), type_(messaging_event::PROTON), parent_event_(0), message_(0) {} messaging_event::messaging_event(event_type t, proton_event &p) : - proton_event(NULL, PN_EVENT_NONE, p.container()), type_(t), parent_event_(&p) + proton_event(NULL, PN_EVENT_NONE, p.container()), type_(t), parent_event_(&p), message_(0) { if (type_ == messaging_event::PROTON) throw error(MSG("invalid messaging event type")); @@ -93,7 +98,7 @@ delivery& messaging_event::delivery() { message &messaging_event::message() { if (type_ != messaging_event::MESSAGE || !parent_event_) throw error(MSG("event type does not provide message")); - return message_; + return *message_; } void messaging_event::dispatch(handler &h) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org