Commit 788aa532 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

heap: Add micro benchmark for Member<> write performance

Adds a micro benchmark for Member<> write performance during and outside
of GC. The test can be used to quantify worst-case scenario for the
Member<> write barrier performance. It can be extended to support
different scenarios (e.g., young generation barrier) in future.

Output on a Z840:
[ RUN      ] WriteBarrierPerfTest.MemberWritePerformance
*RESULT WriteBarrierPerfTest writes during GC: = 21781.746896101067 writes/ms
*RESULT WriteBarrierPerfTest writes outside GC: = 476190.4761904762 writes/ms
*RESULT WriteBarrierPerfTest relative speed difference: = 21.861904761904764 times
[       OK ] WriteBarrierPerfTest.MemberWritePerformance (37 ms)

Bug: 1014414
Change-Id: I565564fe3436fbe610c4724d413d4566b289b3fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1862274Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarAnton Bikineev <bikineev@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705911}
parent f89d7ea5
......@@ -139,6 +139,7 @@ jumbo_source_set("blink_heap_unittests_sources") {
"persistent_test.cc",
"thread_state_scheduling_test.cc",
"worklist_test.cc",
"write_barrier_perftest.cc",
]
configs += [
......
......@@ -13,6 +13,7 @@ include_rules = [
"+base/synchronization/lock.h",
"+base/task_runner.h",
"+base/template_util.h",
"+testing/perf/perf_test.h",
"+third_party/blink/renderer/platform/bindings",
"+third_party/blink/renderer/platform/instrumentation/histogram.h",
......
// Copyright (c) 2019 The Chromium 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 "base/callback.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_test.h"
#include "third_party/blink/renderer/platform/heap/heap_test_utilities.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
namespace blink {
class WriteBarrierPerfTest : public TestSupportingGC {};
namespace {
class SimpleObject : public GarbageCollected<SimpleObject> {
public:
SimpleObject() = default;
virtual void Trace(Visitor*) {}
};
base::TimeDelta TimedRun(base::RepeatingCallback<void()> callback) {
const base::TimeTicks start = base::TimeTicks::Now();
callback.Run();
return base::TimeTicks::Now() - start;
}
} // namespace
TEST_F(WriteBarrierPerfTest, MemberWritePerformance) {
// Setup.
constexpr wtf_size_t kNumElements = 100000;
Persistent<HeapVector<Member<SimpleObject>>> holder(
MakeGarbageCollected<HeapVector<Member<SimpleObject>>>());
for (wtf_size_t i = 0; i < kNumElements; ++i) {
holder->push_back(MakeGarbageCollected<SimpleObject>());
}
PreciselyCollectGarbage();
// Benchmark.
base::RepeatingCallback<void()> benchmark = base::BindRepeating(
[](const Persistent<HeapVector<Member<SimpleObject>>>& holder) {
for (wtf_size_t i = 0; i < kNumElements / 2; ++i) {
(*holder)[i].Swap((*holder)[kNumElements / 2 + i]);
}
},
holder);
// During GC.
IncrementalMarkingTestDriver driver(ThreadState::Current());
driver.Start();
base::TimeDelta during_gc_duration = TimedRun(benchmark);
driver.FinishSteps();
PreciselyCollectGarbage();
// Outside GC.
base::TimeDelta outside_gc_duration = TimedRun(benchmark);
// Cleanup.
holder.Clear();
PreciselyCollectGarbage();
// Reporting.
perf_test::PrintResult(
"WriteBarrierPerfTest", " writes during GC", "",
static_cast<double>(kNumElements) / during_gc_duration.InMillisecondsF(),
"writes/ms", true);
perf_test::PrintResult(
"WriteBarrierPerfTest", " writes outside GC", "",
static_cast<double>(kNumElements) / outside_gc_duration.InMillisecondsF(),
"writes/ms", true);
perf_test::PrintResult("WriteBarrierPerfTest", " relative speed difference",
"",
during_gc_duration.InMillisecondsF() /
outside_gc_duration.InMillisecondsF(),
"times", true);
}
} // namespace blink
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