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>>:
$ heaptrack_print heaptrack.clang++.baseline.gz | tail -n 6 ; heaptrack_print heaptrack.clang++.proposed.gz | tail -n 6 total runtime: 11.76s. calls to allocation functions: 2951292 (250981/s) temporary memory allocations: 608175 (51719/s) peak heap memory consumption: 231.36MB peak RSS (including heaptrack overhead): 399.31MB total memory leaked: 204.39MB
Migrating std::map<std::string, std::string> to StringMap<SmallString<16>> improves things:
total runtime: 11.33s. calls to allocation functions: 2684647 (236908/s) temporary memory allocations: 643713 (56804/s) peak heap memory consumption: 231.44MB peak RSS (including heaptrack overhead): 397.13MB total memory leaked: 204.47MB $ heaptrack_print -d heaptrack.clang++.baseline.gz heaptrack.clang++.proposed.gz | tail -n 6 total runtime: -0.43s. # -3.66 % calls to allocation functions: -266645 (624461/s) # -9.03 % (!) temporary memory allocations: 35538 (-83227/s) # +5.84 % (:/) peak heap memory consumption: 81.71KB peak RSS (including heaptrack overhead): 0B total memory leaked: 81.71KB
I'm a bit confused that SmallString gives an improvement in the number of allocations. All modern standard libraries implement std::string with SSO, so std::string should behave identically to SmallString<16>. What standard library did you test this with?