Commit 4e93f078 authored by Sergei Glazunov's avatar Sergei Glazunov Committed by Chromium LUCI CQ

Eliminate unnecessary Adjust{Size|Offset}ForExtras* calls

This CL fixes a performance regression introduced by r829145.

When both partition cookies and reference counts are disabled at
compile time (which is the current default configuration),
|AdjustSizeForExtrasAdd| and similar functions become no-op.

Make the compiler aware of that.

Bug: 1150917
Change-Id: I24e91177d4575a5ea013a9c647641c6389aa01a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2571281Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Commit-Queue: Sergei Glazunov <glazunov@google.com>
Cr-Commit-Position: refs/heads/master@{#833310}
parent 62bf3786
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
#include <windows.h> #include <windows.h>
#endif #endif
#define PARTITION_EXTRAS_REQUIRED \
(DCHECK_IS_ON() || ENABLE_REF_COUNT_FOR_BACKUP_REF_PTR)
namespace base { namespace base {
namespace internal { namespace internal {
......
...@@ -355,6 +355,7 @@ void PartitionRoot<thread_safe>::Init(PartitionOptions opts) { ...@@ -355,6 +355,7 @@ void PartitionRoot<thread_safe>::Init(PartitionOptions opts) {
// ref-count at the beginning of the slot. // ref-count at the beginning of the slot.
allow_extras = (opts.alignment != PartitionOptions::Alignment::kAlignedAlloc); allow_extras = (opts.alignment != PartitionOptions::Alignment::kAlignedAlloc);
#if PARTITION_EXTRAS_REQUIRED
size_t size = 0, offset = 0; size_t size = 0, offset = 0;
if (allow_extras) { if (allow_extras) {
size += internal::kPartitionCookieSizeAdjustment; size += internal::kPartitionCookieSizeAdjustment;
...@@ -365,6 +366,7 @@ void PartitionRoot<thread_safe>::Init(PartitionOptions opts) { ...@@ -365,6 +366,7 @@ void PartitionRoot<thread_safe>::Init(PartitionOptions opts) {
} }
extras_size = static_cast<uint32_t>(size); extras_size = static_cast<uint32_t>(size);
extras_offset = static_cast<uint32_t>(offset); extras_offset = static_cast<uint32_t>(offset);
#endif
pcscan_mode = PartitionOptionsToPCScanMode<thread_safe>(opts.pcscan); pcscan_mode = PartitionOptionsToPCScanMode<thread_safe>(opts.pcscan);
if (pcscan_mode == PCScanMode::kEnabled) { if (pcscan_mode == PCScanMode::kEnabled) {
......
...@@ -146,8 +146,16 @@ struct BASE_EXPORT PartitionRoot { ...@@ -146,8 +146,16 @@ struct BASE_EXPORT PartitionRoot {
const bool is_thread_safe = thread_safe; const bool is_thread_safe = thread_safe;
bool allow_extras; bool allow_extras;
#if !PARTITION_EXTRAS_REQUIRED
// Teach the compiler that `AdjustSizeForExtrasAdd` etc. can be eliminated
// in builds that use no extras.
static constexpr uint32_t extras_size = 0;
static constexpr uint32_t extras_offset = 0;
#else
uint32_t extras_size; uint32_t extras_size;
uint32_t extras_offset; uint32_t extras_offset;
#endif
// Not used on the fastest path (thread cache allocations), but on the fast // Not used on the fastest path (thread cache allocations), but on the fast
// path of the central allocator. // path of the central allocator.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment