[llvm] r256776 - [PGO]: reserve space for string to avoid excessive memory realloc/copy (non linear)
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 4 12:43:08 PST 2016
On Mon, Jan 4, 2016 at 12:36 PM, Benjamin Kramer via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> 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.
The patch was to solve the original problem of non-linear behavior -- but
you are right using auto still causes overhead (where iterator based
interface should be used).
> Please just use join() from
> StringExtras.h instead of duplicating that code here.
>
Great -- that is exactly the interface needed.
thanks,
David
>
> - 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
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160104/d817527d/attachment.html>
More information about the llvm-commits
mailing list