<div dir="ltr">Yes, I should've mention that in the commit message.<div><br></div><div>And this is probably a sign that we should split StringRef::find into the fast pass (which works on short strings) and the slow pass (which does BM-ish string search) and move the fast pass from StringRef.cpp to StringRef.h, so that they are inlined and optimized by compilers. I'll do that when I have time.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 12, 2017 at 2:09 PM, Rafael Avila de Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I can reproduce the speedup on various benchmarks.<br>
<br>
But note that it is not just a faster algorithm. The old version would<br>
produce a different result for foo@bar@@zed. That is fine for us, but we<br>
couldn't do the same as a special case for small needles in StringRef.<br>
<br>
Thanks,<br>
Rafael<br>
<div class="HOEnZb"><div class="h5"><br>
Rui Ueyama via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> writes:<br>
<br>
> Author: ruiu<br>
> Date: Mon Sep 25 21:17:13 2017<br>
> New Revision: 314192<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=314192&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=314192&view=rev</a><br>
> Log:<br>
> Speed up SymbolTable::insert().<br>
><br>
> SymbolTable::insert() is a hot path function. When linking a clang debug<br>
> build, the function is called 3.7 million times. The total amount of "Name"<br>
> string contents is 300 MiB. That means this `Name.find("@@")` scans almost<br>
> 300 MiB of data. That's far from negligible.<br>
><br>
> StringRef::find(StringRef) uses a sophisticated algorithm, but the<br>
> function is slow for a short needle. This patch replaces it with<br>
> StringRef::find(char).<br>
><br>
> This patch alone speeds up a clang debug build link time by 0.5 seconds<br>
> from 8.2s to 7.7s. That's 6% speed up. It seems too good for this tiny<br>
> change, but looks like it's real.<br>
><br>
> Modified:<br>
>     lld/trunk/ELF/SymbolTable.cpp<br>
><br>
> Modified: lld/trunk/ELF/SymbolTable.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=314192&r1=314191&r2=314192&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>SymbolTable.cpp?rev=314192&r1=<wbr>314191&r2=314192&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/ELF/SymbolTable.cpp (original)<br>
> +++ lld/trunk/ELF/SymbolTable.cpp Mon Sep 25 21:17:13 2017<br>
> @@ -206,8 +206,12 @@ static uint8_t getMinVisibility(uint8_t<br>
>  std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name) {<br>
>    // <name>@@<version> means the symbol is the default version. In that<br>
>    // case <name>@@<version> will be used to resolve references to <name>.<br>
> -  size_t Pos = Name.find("@@");<br>
> -  if (Pos != StringRef::npos)<br>
> +  //<br>
> +  // Since this is a hot path, the following string search code is<br>
> +  // optimized for speed. StringRef::find(char) is much faster than<br>
> +  // StringRef::find(StringRef).<br>
> +  size_t Pos = Name.find('@');<br>
> +  if (Pos != StringRef::npos && Pos + 1 < Name.size() && Name[Pos + 1] == '@')<br>
>      Name = Name.take_front(Pos);<br>
><br>
>    auto P = Symtab.insert(<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>