Skip to content

Commit

Permalink
Add Prefetchers to Proto Copy Construct to help address load misses
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 655292932
  • Loading branch information
Nelson Liang authored and copybara-github committed Jul 23, 2024
1 parent 9e34d5f commit cdb7238
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/google/protobuf/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ using type_info = ::type_info;

#include "absl/base/attributes.h"
#include "absl/base/macros.h"
#include "absl/base/optimization.h"
#include "absl/base/prefetch.h"
#include "absl/log/absl_check.h"
#include "absl/utility/internal/if_constexpr.h"
#include "google/protobuf/arena_align.h"
Expand Down Expand Up @@ -665,6 +667,12 @@ PROTOBUF_NOINLINE void* Arena::DefaultConstruct(Arena* arena) {

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

0 comments on commit cdb7238

Please sign in to comment.