[PATCH] D60792: Time profiler: optimize json output time
Anton Afanasyev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 12:52:30 PDT 2019
anton-afanasyev created this revision.
anton-afanasyev added a reviewer: lebedev.ri.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
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%.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D60792
Files:
llvm/lib/Support/TimeProfiler.cpp
Index: llvm/lib/Support/TimeProfiler.cpp
===================================================================
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -89,6 +89,7 @@
"All profiler sections should be ended when calling Write");
json::Array Events;
+ Events.reserve(Entries.size() + CountAndTotalPerName.size() + 1);
// Emit all events for the main flame graph.
for (const auto &E : Entries) {
@@ -149,6 +150,7 @@
{"args", json::Object{{"name", "clang"}}},
});
+ assert((Entries.size() + CountAndTotalPerName.size() + 1 == Events.size()) && "Events reserved size should be enough!");
OS << formatv("{0:2}", json::Value(json::Object(
{{"traceEvents", std::move(Events)}})));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60792.195439.patch
Type: text/x-patch
Size: 804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190416/94696107/attachment.bin>
More information about the llvm-commits
mailing list