[PATCH] D81335: [IR] AttrBuilder: change TargetDepAttrs to StringMap<SmallString<16>>

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 6 15:28:58 PDT 2020


lebedev.ri created this revision.
lebedev.ri added reviewers: efriedma, nikic, bkramer.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.
lebedev.ri edited the summary of this revision.

Looking at memory footprint of unity build of RawSpeed library
(`-O3 -g0 -emit-llvm -Xclang -disable-llvm-optzns`),
surprisingly `AttrBuilder` is top-1 in memory allocations,
which is not that surprising since it's a `std::map<std::string, std::string>`

Let's see what is the baseline memory footprint,
and what happens with just `StringMap<std::string>`/`StringMap<SmallString<N>>`:

  $ for i in heaptrack.clang++.{baseline,stringmap-of-stdstring,stringmap-of-smallstring-8,stringmap-of-smallstring-16,stringmap-of-smallstring-32}.gz; do echo $i; heaptrack_print $i | tail -n 7; echo "" ; done
  heaptrack.clang++.baseline.gz
  
  total runtime: 26.93s.
  calls to allocation functions: 2955578 (109750/s)
  temporary memory allocations: 612191 (22732/s)
  peak heap memory consumption: 231.36MB
  peak RSS (including heaptrack overhead): 412.57MB
  total memory leaked: 204.39MB
  
  heaptrack.clang++.stringmap-of-stdstring.gz
  
  total runtime: 25.45s.
  calls to allocation functions: 2700335 (106091/s)
  temporary memory allocations: 665166 (26133/s)
  peak heap memory consumption: 231.44MB
  peak RSS (including heaptrack overhead): 411.52MB
  total memory leaked: 204.47MB
  
  heaptrack.clang++.stringmap-of-smallstring-8.gz
  
  total runtime: 26.03s.
  calls to allocation functions: 2691831 (103396/s)
  temporary memory allocations: 647242 (24861/s)
  peak heap memory consumption: 231.44MB
  peak RSS (including heaptrack overhead): 409.85MB
  total memory leaked: 204.47MB
  
  heaptrack.clang++.stringmap-of-smallstring-16.gz
  
  total runtime: 25.67s.
  calls to allocation functions: 2690075 (104798/s)
  temporary memory allocations: 645928 (25163/s)
  peak heap memory consumption: 231.44MB
  peak RSS (including heaptrack overhead): 409.94MB
  total memory leaked: 204.47MB
  
  heaptrack.clang++.stringmap-of-smallstring-32.gz
  
  total runtime: 26.02s.
  calls to allocation functions: 2685612 (103229/s)
  temporary memory allocations: 647885 (24903/s)
  peak heap memory consumption: 231.44MB
  peak RSS (including heaptrack overhead): 409.50MB
  total memory leaked: 204.47MB

Migrating `std::map<std::string, std::string>` to `StringMap<std::string>` improves things:

  $ heaptrack_print -d heaptrack.clang++.baseline.gz heaptrack.clang++.stringmap-of-stdstring.gz | tail -n 6
  total runtime: -1.48s.
  calls to allocation functions: -255243 (172811/s)
  temporary memory allocations: 52975 (-35866/s)
  peak heap memory consumption: 81.75KB
  peak RSS (including heaptrack overhead): 0B
  total memory leaked: 81.75KB

Migrating `StringMap<std::string>` to `StringMap<SmallString<16>>` improves things again:

  $ heaptrack_print -d  heaptrack.clang++.stringmap-of-stdstring.gz heaptrack.clang++.stringmap-of-smallstring-16.gz | tail -n 6
  total runtime: 0.22s.
  calls to allocation functions: -10260 (-47500/s)
  temporary memory allocations: -19238 (-89064/s)
  peak heap memory consumption: -36B
  peak RSS (including heaptrack overhead): 0B
  total memory leaked: -36B

But migrating `StringMap<SmallString<16>>` to `StringMap<SmallString<32>>` isn't really a win:

  $ heaptrack_print -d  heaptrack.clang++.stringmap-of-smallstring-16.gz heaptrack.clang++.stringmap-of-smallstring-32.gz | tail -n 6
  total runtime: 0.35s.
  calls to allocation functions: -4463 (-12861/s)
  temporary memory allocations: 1957 (5639/s)
  peak heap memory consumption: 0B
  peak RSS (including heaptrack overhead): 0B
  total memory leaked: 0B

And likewise migrating `StringMap<SmallString<16>>` to `StringMap<SmallString<8>>` isn't really a win:

  $ heaptrack_print -d  heaptrack.clang++.stringmap-of-smallstring-16.gz heaptrack.clang++.stringmap-of-smallstring-8.gz | tail -n 6
  total runtime: 0.36s.
  calls to allocation functions: 1756 (4810/s)
  temporary memory allocations: 1314 (3600/s)
  peak heap memory consumption: 0B
  peak RSS (including heaptrack overhead): 0B
  total memory leaked: 0B

So `StringMap<SmallString<16>>` appears best:

  $ heaptrack_print -d  heaptrack.clang++.baseline.gz heaptrack.clang++.stringmap-of-smallstring-16.gz  | tail -n 6
  total runtime: -1.26s.
  calls to allocation functions: -265503 (210549/s)
  temporary memory allocations: 33737 (-26754/s)
  peak heap memory consumption: 81.71KB
  peak RSS (including heaptrack overhead): 0B
  total memory leaked: 81.71KB


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81335

Files:
  llvm/include/llvm/IR/Attributes.h
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/AutoUpgrade.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81335.269031.patch
Type: text/x-patch
Size: 3741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200606/153152cf/attachment.bin>


More information about the llvm-commits mailing list