[lld] r329453 - Avoid some temporary allocations.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 6 14:07:15 PDT 2018


 If you move the buffer to the class definition of SharedFile, you can remove
the last call of Saver.save() as well.

On Fri, Apr 6, 2018 at 1:56 PM Rafael Espindola via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: rafael
> Date: Fri Apr  6 13:53:06 2018
> New Revision: 329453
>
> URL: http://llvm.org/viewvc/llvm-project?rev=329453&view=rev
> Log:
> Avoid some temporary allocations.
>
> Some system libraries have a lot of versioned symbols. When linking
> scylla this brings the number of malloc calls from 49154 to 37944.
>
> Modified:
>     lld/trunk/ELF/InputFiles.cpp
>
> Modified: lld/trunk/ELF/InputFiles.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=329453&r1=329452&r2=329453&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/InputFiles.cpp (original)
> +++ lld/trunk/ELF/InputFiles.cpp Fri Apr  6 13:53:06 2018
> @@ -906,6 +906,11 @@ template <class ELFT> void SharedFile<EL
>    std::vector<uint32_t> Versyms = parseVersyms(); // parse .gnu.version
>    ArrayRef<Elf_Shdr> Sections = CHECK(this->getObj().sections(), this);
>
> +  // System libraries can have a lot of symbols with versions. Using a
> +  // fixed buffer for computing the versions name (foo at ver) can save a
> +  // lot of allocations.
> +  SmallString<0> VersionedNameBuffer;
> +
>    // Add symbols to the symbol table.
>    ArrayRef<Elf_Sym> Syms = this->getGlobalELFSyms();
>    for (size_t I = 0; I < Syms.size(); ++I) {
> @@ -956,8 +961,9 @@ template <class ELFT> void SharedFile<EL
>
>      StringRef VerName =
>          this->StringTable.data() + Verdefs[Idx]->getAux()->vda_name;
> -    Name = Saver.save(Name + "@" + VerName);
> -    Symtab->addShared(Name, *this, Sym, Alignment, Idx);
> +    VersionedNameBuffer.clear();
> +    Name = (Name + "@" + VerName).toStringRef(VersionedNameBuffer);
> +    Symtab->addShared(Saver.save(Name), *this, Sym, Alignment, Idx);
>    }
>  }
>
>
>
> _______________________________________________
> 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/20180406/61ca4053/attachment.html>


More information about the llvm-commits mailing list