<div dir="ltr">Hi Erik,<div><br></div><div>Thanks for working on this!<br></div><div><div class="gmail_extra"><br><div class="gmail_quote">2017-06-21 16:42 GMT-07:00 Erik Pilkington via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello all,<br>
The itanium demangler in libcxxabi (and also, llvm/lib/Demangle) is really slow. This is largely because the textual representation of the symbol that is being demangled is held in a std::string, and manipulations done during parsing are done on that string. The demangler is always concatenating strings and inserting into the middle of strings, which is terrible. The fact that the parsing logic and the string manipulation/formatting logic is interleaved also makes the demangler pretty ugly. Another problem was that the demangler used a lot stack space, and has a bunch of stack overflows filed against it.<br>
<br>
I've been working on fixing this by parsing first into an AST structure, and then traversing that AST to produce a demangled string. This provides a significant performance improvement and also make the demangler somewhat more clean. Attached you should find a patch to this effect. This patch is still very much a work in progress, but currently passes the libcxxabi test suite and demangles all the symbols in LLVM identically to the current demangler. It also provides a significant performance improvement: it demangles the symbols in LLVM about 3.7 times faster than the current demangler. Also, separating the formatting code from the parser reduces stack usage (the activation frame for parse_type reduced from 416 to 144 bytes on my machine). The stack usage is still pretty bad, but this helps with some of it.<br>
<br>
Does anyone have any early feedback on the patch? Does this seem like a good direction for the demangler?<br></blockquote><div><br></div><div>+David Majnemer who had some opinion about the direction.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
As far as future plans for this file, I have a few more refactorings and performance improvements that I'd like to get through. After that, it might be interesting to try to replace the FastDemangle.cpp demangler in LLDB with this, to restore the one true demangler in the source tree. The FastDemangler.cpp is only partially completed, and calls out to ItaniumDemangle.cpp in llvm (which is a copy of cxa_demangle.cpp) if it fails to parse the symbol.<br>
<br>
Any thoughts here would be appreciated!</blockquote></div><br></div><div class="gmail_extra">I've been frustrated by how terrible the existing libcxxabi demangler was written and documented. I'd really like to see the new one up to the usual LLVM standard in terms of coding style, quality of implementation, and documentation of the code.</div><div class="gmail_extra"><br></div><div class="gmail_extra">-- </div><div class="gmail_extra">Mehdi</div><div class="gmail_extra"><br></div></div></div>