[llvm] r358522 - Time profiler: optimize json output time
Anton Afanasyev via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 13:36:56 PDT 2019
Author: anton-afanasyev
Date: Tue Apr 16 13:36:56 2019
New Revision: 358522
URL: http://llvm.org/viewvc/llvm-project?rev=358522&view=rev
Log:
Time profiler: optimize json output time
Summary:
Use llvm::json::Array.reserve() to optimize json output time. Here is motivation:
https://reviews.llvm.org/D60609#1468941. In short: for the json array
with ~32K entries, pushing back each entry takes ~4% of whole time compared
to the method of preliminary memory reservation: (3995-3845)/3995 = 3.75%.
Reviewers: lebedev.ri
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60792
Modified:
llvm/trunk/lib/Support/TimeProfiler.cpp
Modified: llvm/trunk/lib/Support/TimeProfiler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/TimeProfiler.cpp?rev=358522&r1=358521&r2=358522&view=diff
==============================================================================
--- llvm/trunk/lib/Support/TimeProfiler.cpp (original)
+++ llvm/trunk/lib/Support/TimeProfiler.cpp Tue Apr 16 13:36:56 2019
@@ -89,6 +89,9 @@ struct TimeTraceProfiler {
"All profiler sections should be ended when calling Write");
json::Array Events;
+ const size_t ExpectedEntryCount =
+ Entries.size() + CountAndTotalPerName.size() + 1;
+ Events.reserve(ExpectedEntryCount);
// Emit all events for the main flame graph.
for (const auto &E : Entries) {
@@ -149,6 +152,8 @@ struct TimeTraceProfiler {
{"args", json::Object{{"name", "clang"}}},
});
+ assert(Events.size() == ExpectedEntryCount && "Size prediction failed!");
+
OS << formatv("{0:2}", json::Value(json::Object(
{{"traceEvents", std::move(Events)}})));
}
More information about the llvm-commits
mailing list