From db861a254623228468c736a17b13af1d4afdc112 Mon Sep 17 00:00:00 2001 From: Arjun Roy Date: Mon, 9 Sep 2019 12:07:00 -0700 Subject: [PATCH] Coalesced arena allocs in callback unary C++ code. --- .../grpcpp/impl/codegen/client_callback_impl.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/grpcpp/impl/codegen/client_callback_impl.h b/include/grpcpp/impl/codegen/client_callback_impl.h index 37746ef5ce4..34c738ac1e6 100644 --- a/include/grpcpp/impl/codegen/client_callback_impl.h +++ b/include/grpcpp/impl/codegen/client_callback_impl.h @@ -72,11 +72,16 @@ class CallbackUnaryCallImpl { grpc::internal::CallOpClientSendClose, grpc::internal::CallOpClientRecvStatus>; - auto* ops = new (::grpc::g_core_codegen_interface->grpc_call_arena_alloc( - call.call(), sizeof(FullCallOpSet))) FullCallOpSet; - - auto* tag = new (::grpc::g_core_codegen_interface->grpc_call_arena_alloc( - call.call(), sizeof(grpc::internal::CallbackWithStatusTag))) + struct OpSetAndTag { + FullCallOpSet opset; + grpc::internal::CallbackWithStatusTag tag; + }; + const size_t alloc_sz = sizeof(OpSetAndTag); + auto* const alloced = static_cast( + ::grpc::g_core_codegen_interface->grpc_call_arena_alloc(call.call(), + alloc_sz)); + auto* ops = new (&alloced->opset) FullCallOpSet; + auto* tag = new (&alloced->tag) grpc::internal::CallbackWithStatusTag(call.call(), on_completion, ops); // TODO(vjpai): Unify code with sync API as much as possible