Skip to content

Commit cdb7238

Browse files
NL02copybara-github
authored andcommitted
Add Prefetchers to Proto Copy Construct to help address load misses
PiperOrigin-RevId: 655292932
1 parent 9e34d5f commit cdb7238

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/google/protobuf/arena.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ using type_info = ::type_info;
2929

3030
#include "absl/base/attributes.h"
3131
#include "absl/base/macros.h"
32+
#include "absl/base/optimization.h"
33+
#include "absl/base/prefetch.h"
3234
#include "absl/log/absl_check.h"
3335
#include "absl/utility/internal/if_constexpr.h"
3436
#include "google/protobuf/arena_align.h"
@@ -665,6 +667,12 @@ PROTOBUF_NOINLINE void* Arena::DefaultConstruct(Arena* arena) {
665667

666668
template <typename T>
667669
PROTOBUF_NOINLINE void* Arena::CopyConstruct(Arena* arena, const void* from) {
670+
// If the object is larger than half a cache line, prefetch it.
671+
// This way of prefetching is a little more aggressive than if we
672+
// condition off a whole cache line, but benchmarks show better results.
673+
if (sizeof(T) > ABSL_CACHELINE_SIZE / 2) {
674+
PROTOBUF_PREFETCH_WITH_OFFSET(from, 64);
675+
}
668676
static_assert(is_destructor_skippable<T>::value, "");
669677
void* mem = arena != nullptr ? arena->AllocateAligned(sizeof(T))
670678
: ::operator new(sizeof(T));

0 commit comments

Comments
 (0)