Enable Arena Enabled Copy Constructor for RepeatedPtrField

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
pull/14449/head
Martijn Vels 1 year ago committed by Copybara-Service
parent 9831212313
commit 8908ea9aff
  1. 4
      src/google/protobuf/repeated_ptr_field.h

@ -311,9 +311,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
// Message creating functor: used in MergeFrom<T>()
template <typename T>
static MessageLite* CopyMessage(Arena* arena, const MessageLite& src) {
T* msg = Arena::CreateMaybeMessage<T>(arena);
msg->MergeFrom(static_cast<const T&>(src));
return msg;
return Arena::CreateMaybeMessage<T>(arena, static_cast<const T&>(src));
}
// Appends all message values from `from` to this instance.

Loading…
Cancel
Save