[llvm] r256776 - [PGO]: reserve space for string to avoid excessive memory realloc/copy (non linear)

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 4 12:36:12 PST 2016


On Mon, Jan 4, 2016 at 9:26 PM, Xinliang David Li via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: davidxl
> Date: Mon Jan  4 14:26:05 2016
> New Revision: 256776
>
> URL: http://llvm.org/viewvc/llvm-project?rev=256776&view=rev
> Log:
> [PGO]: reserve space for string to avoid excessive memory realloc/copy (non linear)
>
> Modified:
>     llvm/trunk/lib/ProfileData/InstrProf.cpp
>
> Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=256776&r1=256775&r2=256776&view=diff
> ==============================================================================
> --- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
> +++ llvm/trunk/lib/ProfileData/InstrProf.cpp Mon Jan  4 14:26:05 2016
> @@ -168,6 +168,12 @@ int collectPGOFuncNameStrings(const std:
>                                bool doCompression, std::string &Result) {
>    uint8_t Header[16], *P = Header;
>    std::string UncompressedNameStrings;
> +  size_t UncompressedStringLen = 0;
> +
> +  for (auto NameStr : NameStrs)
> +    UncompressedStringLen += (NameStr.length() + 1);
> +
> +  UncompressedNameStrings.reserve(UncompressedStringLen + 1);

This still does excessive copying, "auto NameStr" will create a copy
of the string on every iteration. Please just use join() from
StringExtras.h instead of duplicating that code here.

- Ben

>
>    for (auto NameStr : NameStrs) {
>      UncompressedNameStrings += NameStr;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list