This is an archive of the discontinued LLVM Phabricator instance.

[llvm-exegesis] InstructionBenchmarkClustering::rangeQuery(): write into llvm::SmallVectorImpl& output parameter
ClosedPublic

Authored by lebedev.ri on Nov 11 2018, 3:07 AM.

Details

Summary

I do believe this is the correct fix.
We call rangeQuery() *very* often. And many times it's output vector is large (tens of thousands entries), so small-size-opt won't help.

Old: (D54389)

 Performance counter stats for './bin/llvm-exegesis -mode=analysis -analysis-epsilon=100000 -benchmarks-file=/tmp/benchmarks.yaml -analysis-inconsistencies-output-file=/tmp/clusters.html' (10 runs):

       7934.528363      task-clock (msec)         #    1.000 CPUs utilized            ( +-  0.19% )
...
            7.9354 +- 0.0148 seconds time elapsed  ( +-  0.19% )

New:

 Performance counter stats for './bin/llvm-exegesis -mode=analysis -analysis-epsilon=100000 -benchmarks-file=/tmp/benchmarks.yaml -analysis-inconsistencies-output-file=/tmp/clusters.html' (10 runs):

       7383.793440      task-clock (msec)         #    1.000 CPUs utilized            ( +-  0.47% )
...
            7.3868 +- 0.0340 seconds time elapsed  ( +-  0.46% )

And another -7%. And that isn't even the good bit yet.

Old:

  • calls to allocation functions: 2081419
  • temporary allocations: 219658 (10.55%)
  • bytes allocated in total (ignoring deallocations): 4.31 GB

New:

  • calls to allocation functions: 1880295 (-10%)
  • temporary allocations: 18758 (1%) (-91% *sic*)
  • bytes allocated in total (ignoring deallocations): 545.15 MB (-88% *sic*)

Diff Detail

Repository
rL LLVM

Event Timeline

lebedev.ri created this revision.Nov 11 2018, 3:07 AM
MaskRay accepted this revision.Nov 11 2018, 4:26 PM

LG. The issue is that there shouldn't be frequent SmallVector construction/destruction in the loop body.

Here comes my own question: when the specific vector type does not matter too much (as in this case), when shall we choose SmallVector and when std::vector?

This revision is now accepted and ready to land.Nov 11 2018, 4:26 PM
MaskRay added inline comments.Nov 11 2018, 7:06 PM
tools/llvm-exegesis/lib/Clustering.cpp
105

It can be set to of size`NumPoints`

LG. The issue is that there shouldn't be frequent SmallVector construction/destruction in the loop body.

Here comes my own question: when the specific vector type does not matter too much (as in this case), when shall we choose SmallVector and when std::vector?

If there are preexisting contract/interface requirements - the one required by the contract/interface.
Else, if there are no concerns about memory usage, but the element count is hard to guess, SmallVector is much better because it doubles it's capacity.

courbet accepted this revision.Nov 19 2018, 1:55 AM
This comment was removed by lebedev.ri.

LG.

@courbet

Thank you for the reviews!