proto: remove debug logging from opt build

The debug logging call makes SerialArena::AllocateFromExistingWithCleanupFallback  function non-leaf and significantly worsens codegen (stack frame allocation + register spills). As the result it's also not inlined into ThreadSafeArena::AllocateAlignedWithCleanup.

With this change SerialArena::AllocateFromExistingWithCleanupFallback
becomes frame-less leaf function and is inlined into ThreadSafeArena::AllocateAlignedWithCleanup.

Codegen before:

00000000007b1820 <proto2::internal::ThreadSafeArena::AllocateAlignedWithCleanup(unsigned long, unsigned long, void (*)(void*))>:
  7b1820:       48 c7 c0 40 fb ff ff    mov    $0xfffffffffffffb40,%rax
  7b1827:       64 4c 8b 40 08          mov    %fs:0x8(%rax),%r8
...
  7b189f:       e9 5c eb ff ff          jmp    7b0400 <proto2::internal::SerialArena::AllocateFromExistingWithCleanupFallback(unsigned long, unsigned long, void (*)(void*))>

  00000000007b0400 <proto2::internal::SerialArena::AllocateFromExistingWithCleanupFallback(unsigned long, unsigned long, void (*)(void*))>:
  7b0400:	55                   	push   %rbp
  7b0401:	48 89 e5             	mov    %rsp,%rbp
  7b0404:	41 56                	push   %r14
  7b0406:	53                   	push   %rbx
  7b0407:	48 83 ec 10          	sub    $0x10,%rsp
  ...
  7b04c3:	48 83 c4 10          	add    $0x10,%rsp
  7b04c7:	5b                   	pop    %rbx
  7b04c8:	41 5e                	pop    %r14
  7b04ca:	5d                   	pop    %rbp
  7b04cb:	c3                   	ret
  7b04cc:	48 8d 35 44 a4 a9 ff 	lea    -0x565bbc(%rip),%rsi        # 24a917 <absl::debugging_internal::IdentifierIsAnonymousNamespace(absl::debugging_internal::State*, unsigned long)::anon_prefix+0x2e19e>
  7b04d3:	4c 8d 75 e0          	lea    -0x20(%rbp),%r14
  7b04d7:	4c 89 f7             	mov    %r14,%rdi
  7b04da:	ba f3 00 00 00       	mov    $0xf3,%edx
  7b04df:	e8 9c 05 1e 00       	call   990a80 <absl::log_internal::LogMessageFatal::LogMessageFatal(char const*, int)>
  7b04e4:	48 8d 35 3e 43 a6 ff 	lea    -0x59bcc2(%rip),%rsi        # 214829 <absl::Symbolize(void const*, char*, int)::kEllipsis+0xba26>
  7b04eb:	4c 89 f7             	mov    %r14,%rdi
  7b04ee:	e8 cd f6 d0 ff       	call   4bfbc0 <absl::log_internal::LogMessage& absl::log_internal::LogMessage::operator<< <24>(char const (&) [24])>
  7b04f3:	48 89 c7             	mov    %rax,%rdi
  7b04f6:	89 de                	mov    %ebx,%esi
  7b04f8:	e8 c3 a0 c9 ff       	call   44a5c0 <absl::log_internal::LogMessage::operator<<(int)>
  7b04fd:	4c 89 f7             	mov    %r14,%rdi
  7b0500:	e8 1b e9 0c 00       	call   87ee20 <absl::log_internal::LogMessageFatal::~LogMessageFatal()>

Codegen after:

00000000007b1680 <proto2::internal::ThreadSafeArena::AllocateAlignedWithCleanup(unsigned long, unsigned long, void (*)(void*))>:
  7b1680:	49 c7 c0 40 fb ff ff 	mov    $0xfffffffffffffb40,%r8
  7b1687:	64 49 8b 40 08       	mov    %fs:0x8(%r8),%rax
...
  7b17a5:	c3                   	ret

name                           old cpu/op   new cpu/op   delta
BM_ArenaAllocWithCleanup/100   957ns ± 3%   868ns ± 1%  -9.27%  (p=0.000 n=54+48)

PiperOrigin-RevId: 561281492
pull/13788/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 69f86a62f9
commit 89e7b1c7f1
  1. 22
      src/google/protobuf/arena_cleanup.h

@ -199,26 +199,6 @@ inline ABSL_ATTRIBUTE_ALWAYS_INLINE Tag Type(void (*destructor)(void*)) {
return Tag::kDynamic;
}
// Returns the `tag` identifying the type of object stored at memory location
// `elem`, which represents the first uintptr_t value in the node.
inline ABSL_ATTRIBUTE_ALWAYS_INLINE Tag Type(void* raw) {
if (!EnableSpecializedTags()) return Tag::kDynamic;
uintptr_t elem;
memcpy(&elem, raw, sizeof(elem));
switch (static_cast<Tag>(elem & 0x7ULL)) {
case Tag::kDynamic:
return Tag::kDynamic;
case Tag::kString:
return Tag::kString;
case Tag::kCord:
return Tag::kCord;
default:
ABSL_LOG(FATAL) << "Corrupted cleanup tag: " << (elem & 0x7ULL);
return Tag::kDynamic;
}
}
// Returns the required size in bytes off the node type identified by `tag`.
inline ABSL_ATTRIBUTE_ALWAYS_INLINE size_t Size(Tag tag) {
if (!EnableSpecializedTags()) return sizeof(DynamicNode);
@ -231,7 +211,7 @@ inline ABSL_ATTRIBUTE_ALWAYS_INLINE size_t Size(Tag tag) {
case Tag::kCord:
return sizeof(TaggedNode);
default:
ABSL_LOG(FATAL) << "Corrupted cleanup tag: " << static_cast<int>(tag);
ABSL_DCHECK(false) << "Corrupted cleanup tag: " << static_cast<int>(tag);
return sizeof(DynamicNode);
}
}

Loading…
Cancel
Save