Commit 5ab27690 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

cppgc: Add micro benchmark for tracing objects

The benchmarks cover static vs dynamic tracing of an object where the
header is computed statically vs using the object start bitmap,
respectively.

$ out/x64.release/cppgc_basic_benchmarks --benchmark_filter=Trace/*

Running out/x64.release/cppgc_basic_benchmarks
Run on (56 X 3500 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x28)
  L1 Instruction 32 KiB (x28)
  L2 Unified 256 KiB (x28)
  L3 Unified 35840 KiB (x2)
Load Average: 0.24, 0.26, 0.26
--------------------------------------------------------
Benchmark              Time             CPU   Iterations
--------------------------------------------------------
Trace/Static        1.78 ns         1.78 ns    393324147
Trace/Dynamic       3.27 ns         3.27 ns    215078276

2020-07-03T15: 21:25+02:00
Change-Id: I8bf5a8ed71a8991873160353e26f96214c038730
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2280099
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarAnton Bikineev <bikineev@chromium.org>
Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68675}
parent 42a841f8
......@@ -10,7 +10,7 @@ group("gn_all") {
deps = []
if (v8_enable_google_benchmark) {
deps += [ ":cppgc_allocation_benchmark" ]
deps += [ ":cppgc_basic_benchmarks" ]
}
}
......@@ -34,7 +34,7 @@ if (v8_enable_google_benchmark) {
]
}
v8_executable("cppgc_allocation_benchmark") {
v8_executable("cppgc_basic_benchmarks") {
testonly = true
configs = [
......@@ -42,7 +42,10 @@ if (v8_enable_google_benchmark) {
"../../../..:internal_config_base",
"../../../..:cppgc_base_config",
]
sources = [ "allocation_perf.cc" ]
sources = [
"allocation_perf.cc",
"trace_perf.cc",
]
deps = [
":cppgc_benchmark_support",
"../../../..:cppgc_for_testing",
......
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "include/cppgc/allocation.h"
#include "include/cppgc/garbage-collected.h"
#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap.h"
#include "test/benchmarks/cpp/cppgc/utils.h"
#include "third_party/google_benchmark/src/include/benchmark/benchmark.h"
#include "v8config.h"
namespace cppgc {
namespace internal {
namespace {
using Trace = testing::BenchmarkWithHeap;
class GCed : public cppgc::GarbageCollected<GCed> {
public:
virtual void Trace(Visitor*) const {}
};
class OtherPayload {
public:
virtual void* DummyGetter() { return nullptr; }
};
class Mixin : public GarbageCollectedMixin {
public:
void Trace(Visitor*) const override {}
};
class GCedWithMixin final : public GCed, public OtherPayload, public Mixin {
USING_GARBAGE_COLLECTED_MIXIN();
public:
void Trace(Visitor* visitor) const final {
GCed::Trace(visitor);
Mixin::Trace(visitor);
}
};
class Holder : public cppgc::GarbageCollected<GCed> {
public:
explicit Holder(GCedWithMixin* object)
: base_ref(object), mixin_ref(object) {}
virtual void Trace(Visitor* visitor) const {
visitor->Trace(base_ref);
visitor->Trace(mixin_ref);
}
cppgc::Member<GCedWithMixin> base_ref;
cppgc::Member<Mixin> mixin_ref;
};
template <typename T>
V8_NOINLINE void DispatchTrace(Visitor* visitor, T& ref) {
visitor->Trace(ref);
}
BENCHMARK_F(Trace, Static)(benchmark::State& st) {
cppgc::Persistent<Holder> holder(cppgc::MakeGarbageCollected<Holder>(
heap().GetAllocationHandle(), cppgc::MakeGarbageCollected<GCedWithMixin>(
heap().GetAllocationHandle())));
VisitorBase visitor;
for (auto _ : st) {
DispatchTrace(&visitor, holder->base_ref);
}
}
BENCHMARK_F(Trace, Dynamic)(benchmark::State& st) {
cppgc::Persistent<Holder> holder(cppgc::MakeGarbageCollected<Holder>(
heap().GetAllocationHandle(), cppgc::MakeGarbageCollected<GCedWithMixin>(
heap().GetAllocationHandle())));
VisitorBase visitor;
for (auto _ : st) {
DispatchTrace(&visitor, holder->mixin_ref);
}
}
} // namespace
} // namespace internal
} // namespace cppgc
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