From 8908ea9aff5dfab6d1da12ea4e20ecb073cc75f2 Mon Sep 17 00:00:00 2001 From: Martijn Vels Date: Tue, 17 Oct 2023 14:56:58 -0700 Subject: [PATCH] Enable Arena Enabled Copy Constructor for RepeatedPtrField MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Benchmarking has this as a saving of up to 20%: name old cpu/op new cpu/op delta BM_MergeFromMessage/1 830ns ±15% 712ns ±16% -14.22% (p=0.000 n=20+20) BM_MergeFromMessage/10 9.03µs ±13% 7.42µs ±13% -17.91% (p=0.000 n=20+18) BM_MergeFromMessage/100 93.3µs ±16% 76.5µs ± 6% -18.01% (p=0.000 n=20+17) BM_MergeFromMessageWithArena/1 614ns ±16% 478ns ± 3% -22.07% (p=0.000 n=20+16) BM_MergeFromMessageWithArena/10 6.05µs ±14% 4.93µs ±19% -18.53% (p=0.000 n=20+20) BM_MergeFromMessageWithArena/100 59.7µs ±15% 49.3µs ±20% -17.51% (p=0.000 n=20+20) PiperOrigin-RevId: 574274002 --- src/google/protobuf/repeated_ptr_field.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index d38232462e..7a0c0989fe 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -311,9 +311,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // Message creating functor: used in MergeFrom() template static MessageLite* CopyMessage(Arena* arena, const MessageLite& src) { - T* msg = Arena::CreateMaybeMessage(arena); - msg->MergeFrom(static_cast(src)); - return msg; + return Arena::CreateMaybeMessage(arena, static_cast(src)); } // Appends all message values from `from` to this instance.