This is an archive of the discontinued LLVM Phabricator instance.

Time profiler: optimize json output time
ClosedPublic

Authored by anton-afanasyev on Apr 16 2019, 12:51 PM.

Details

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%.

Diff Detail

Repository
rL LLVM

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptApr 16 2019, 12:51 PM

Updated, clang-format

Harbormaster completed remote builds in B30640: Diff 195441.
lebedev.ri accepted this revision.Apr 16 2019, 1:12 PM

LG, thank you.

llvm/lib/Support/TimeProfiler.cpp
92 ↗(On Diff #195441)

Just do

const size_t ExpectedEntryCount = Entries.size() + CountAndTotalPerName.size() + 1;
Events.reserve(ExpectedEntryCount);
...
assert(Events.size() == ExpectedEntryCount && "Size prediction failed");

else they could drift apart.

This revision is now accepted and ready to land.Apr 16 2019, 1:12 PM
anton-afanasyev marked 2 inline comments as done.Apr 16 2019, 1:19 PM
anton-afanasyev added inline comments.
llvm/lib/Support/TimeProfiler.cpp
92 ↗(On Diff #195441)

Thanks, good point!

anton-afanasyev marked an inline comment as done.

Updated assertion

This revision was automatically updated to reflect the committed changes.