Skip to content

Commit

Permalink
Add software prefetch to ByteSizeLong
Browse files Browse the repository at this point in the history
Mkaes ByteSizeLong faster:
BM_ByteSizeLong                   15.7µs ± 4%  14.9µs ± 6%  -5.17%  (p=0.000 n=20+20)

PiperOrigin-RevId: 605067418
  • Loading branch information
TocarIP authored and Copybara-Service committed Feb 7, 2024
1 parent 85a8048 commit 948ca2e
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/google/protobuf/compiler/cpp/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4513,6 +4513,15 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) {
"// Prevent compiler warnings about cached_has_bits being unused\n"
"(void) cached_has_bits;\n\n");

// See comment in third_party/protobuf/port.h for details,
// on how much we are prefetching. Only insert prefetch once per
// function, since advancing is actually slower. We sometimes
// prefetch more than sizeof(message), because it helps with
// next message on arena.
p->Emit(R"cc(
::_pbi::Prefetch5LinesFrom7Lines(reinterpret_cast<const void*>(this));
)cc");

while (it != end) {
auto next = FindNextUnequalChunk(it, end, MayGroupChunksForHaswordsCheck);
bool has_haswords_check = MaybeEmitHaswordsCheck(
Expand Down
1 change: 1 addition & 0 deletions src/google/protobuf/compiler/java/java_features.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/google/protobuf/compiler/plugin.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/google/protobuf/cpp_features.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/google/protobuf/descriptor.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
target = ::proto2::internal::WireFormatLite::
WriteInt32ToArrayWithField<1>(
@@ @@
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;

::_pbi::Prefetch5LinesFrom7Lines(reinterpret_cast<const void*>(this));
- // optional int32 int32_field = 1;
+ // int32 int32_field = 1;
cached_has_bits = _impl_._has_bits_[0];
Expand Down
Loading

0 comments on commit 948ca2e

Please sign in to comment.