<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Adam,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>The test case was the Python-3.6.0b3 release, 234 input YAML files.  The large majority of time is spent with processing the file input.  Next ranked was rendering output.  Moving the files to a tmpfs partition didn’t change the time significantly (but I would expect that experiment would yield different results with libYAML).<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>original, single-threaded:<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>processed input files 335.985792875 secs<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>mapped remarks 0.060357093811 secs<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>file rendering 70.5569140911 sec<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>index rendering 1.79133582115 sec<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>x20 processes spawned:<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>processed input files 53.4612071514 secs<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>mapped remarks 0.0622367858887 secs<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>file rendering 8.30268716812 sec<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>index rendering 2.08150291443 sec<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>total time 63.9999139309 secs<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>-Brian<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org] <b>On Behalf Of </b>Adam Nemet via llvm-dev<br><b>Sent:</b> Thursday, November 17, 2016 11:15 AM<br><b>To:</b> Cain, Brian <bcain@quicinc.com><br><b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org>; Bob Haarman <inglorion@google.com><br><b>Subject:</b> Re: [llvm-dev] Rewriting opt-viewer in C++<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hi Brian,<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Great, thanks for doing this!<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Can you please share the timing printouts?  Are we spending most of the time in parsing?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Is this on an internal test case?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Adam<o:p></o:p></p></div><div><div><p class=MsoNormal><o:p> </o:p></p><div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal>On Nov 16, 2016, at 9:43 PM, Cain, Brian <<a href="mailto:bcain@quicinc.com">bcain@quicinc.com</a>> wrote:<o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>If the decision on whether this should swing Python or C++ is still open, here’s some food for thought: it’s trivially parallelizable.</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>I lobbed some stuff in<span class=apple-converted-space> </span><a href="https://reviews.llvm.org/D26789"><span style='color:purple'>https://reviews.llvm.org/D26789</span></a></span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>I used the pure python PyYAML and got a speedup of ~4x on my test case.  I expect you might still be able to get an improvement with libYAML + a patch like this one.</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>FWIW prior to this I also tried PyPy (w/original opt-viewer.py+pure python PyYAML) and got a very modest improvement.  I haven’t tried revisiting it after parallelization.</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>-Brian</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'> </span><o:p></o:p></p></div><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><div><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span class=apple-converted-space><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> </span></span><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>llvm-dev [<a href="mailto:llvm-dev-bounces@lists.llvm.org">mailto:llvm-dev-bounces@lists.llvm.org</a>]<span class=apple-converted-space> </span><b>On Behalf Of<span class=apple-converted-space> </span></b>Adam Nemet via llvm-dev<br><b>Sent:</b><span class=apple-converted-space> </span>Tuesday, November 15, 2016 10:14 PM<br><b>To:</b><span class=apple-converted-space> </span>Bob Haarman <<a href="mailto:inglorion@google.com">inglorion@google.com</a>><br><b>Cc:</b><span class=apple-converted-space> </span>llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br><b>Subject:</b><span class=apple-converted-space> </span>Re: [llvm-dev] Rewriting opt-viewer in C++</span><o:p></o:p></p></div></div></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><p class=MsoNormal>Well, we’re talking about completely different inputs.  Can you please try the libYAML version with your input and do some profiling to address the comments in this thread.<o:p></o:p></p></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal>There are clear advantages to keeping the tooling around optimization records in Python.  Besides syntax highlighting, there are other tools we can build around it (e.g. diffing tool for performance regression analysis, stats, SQL exporting) so having a Python module (or bindings) to expose this programmatically sounds pretty attractive to me.<o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal>Adam<o:p></o:p></p></div><div><div><div><div><p class=MsoNormal> <o:p></o:p></p></div><div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p class=MsoNormal>On Nov 15, 2016, at 5:55 PM, Bob Haarman <<a href="mailto:inglorion@google.com"><span style='color:purple'>inglorion@google.com</span></a>> wrote:<o:p></o:p></p></div></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><div><div><p class=MsoNormal>That's compared to the implementation with the Python parser. So if the libYAML parser is 6x the speed of that, the C++ version would be about 10x the speed of the implementation with libYAML, instead of 60x.<o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div><div><div><p class=MsoNormal>On Tue, Nov 15, 2016 at 10:50 AM, Adam Nemet <<a href="mailto:anemet@apple.com" target="_blank"><span style='color:purple'>anemet@apple.com</span></a>> wrote:<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'><div><div><p class=MsoNormal> <o:p></o:p></p></div><div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p class=MsoNormal>On Nov 15, 2016, at 10:33 AM, Bob Haarman <<a href="mailto:inglorion@google.com" target="_blank"><span style='color:purple'>inglorion@google.com</span></a>> wrote:<o:p></o:p></p></div></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><div><div><p class=MsoNormal>Thanks for your comments, everyone! I'll try to answer the questions people have asked. First, let me say that I like Python, so I would be happy to keep the tool in Python if people feel that is a better way to go and we can still get it to go fast. As for precedent, we have several Python scripts already shipping with LLVM, including lit, and Python is listed in the requirements, so I imagine it's fine from that perspective.<br><br>Having said that, the C++ version is quite a lot faster. I'm seeing about a 60x difference in how long it takes to generate HTML. This is with the C++ version doing a bit more work - specifically, it correctly encodes characters that have special meaning to HTML. I've been testing this on a build of the Chromium web browser with reports for the inline pass. On my machine, processing only the storage directory takes about 7 seconds with the C++ version and about 6 minutes and 20 seconds with the Python version. The v8 directory takes about 35 seconds with the C++ version and 44 minutes with the Python version. Processing the whole build takes about 13 minutes with the C++ version; when I tried it with the Python version over night, it was still going 14 hours later.<o:p></o:p></p></div></div></div></blockquote><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal>Is this compared against the libYAML parser or the original Python parser?  See my mail from last night.<o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='color:#888888'> </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='color:#888888'>Adam</span><o:p></o:p></p></div></div><div><p class=MsoNormal><br><br><br><o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p class=MsoNormal style='margin-bottom:12.0pt'>The way I would like to use the tool is to perform a compilation and then look at the optimization report to look at which optimizations were missed and why, then change the code and/or the compiler to see if we can get faster code to be emitted. Ideally, I would like to have the optimization report ready for viewing soon after the compilation. Being able to generate the report in seconds, or less than a second, is definitely more useful to my use case than taking minutes. I figured we might get a good speedup from rewriting the tool in C++, and if we ever were going to do that, it would be easier to do it when the tool was relatively simple, as it is now. I believe my rewrite is complete now, and I think the increase in speed actually makes the tool more useful in that it can now feasibly be used on larger projects. I'll clean up the code a bit (it's very much proof of concept now) and put it up for review once that's done.<br><br>Bob<br><br><br><o:p></o:p></p></div><div><div><p class=MsoNormal> <o:p></o:p></p></div><div><div><p class=MsoNormal>On Mon, Nov 14, 2016 at 9:12 AM, Adam Nemet <<a href="mailto:anemet@apple.com" target="_blank"><span style='color:purple'>anemet@apple.com</span></a>> wrote:<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'><div><div><div><p class=MsoNormal>Again I am still undecided which way this should go but I was also wondering about the speed difference if we used the C-based parser in PyYAML (<a href="http://pyyaml.org/wiki/LibYAML" target="_blank"><span style='color:purple'>http://pyyaml.org/wiki/LibYAML</span></a>).<o:p></o:p></p></div></div><div><div><div><p class=MsoNormal> <o:p></o:p></p></div><div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p class=MsoNormal>On Nov 13, 2016, at 12:19 AM, Adam Nemet <<a href="mailto:anemet@apple.com" target="_blank"><span style='color:purple'>anemet@apple.com</span></a>> wrote:<o:p></o:p></p></div></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><div><div><p class=MsoNormal>Hi Bob,<o:p></o:p></p></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal>I am glad you’re finding opt-viewer useful.  I am generally fine this being rewritten in C++.  The idea was that once the prototype proves itself to be useful this would be considered.<o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal>Do you have ideas how to get syntax highlighting implemented?  In Python, Pygments makes this easy.<o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal>Another usage model I was considering is for people who ssh to remote servers for their builds.  In this case it should be easy in Python to have  a simple HTTP server started in opt-viewer.<o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal>On the other hand, I am not sure if we have precedence to ship tools written in Python in LLVM so we may *have to* move. <o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal>Adam<o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div><div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p class=MsoNormal>On Nov 11, 2016, at 11:50 PM, Bob Haarman <<a href="mailto:llvm@inglorion.net" target="_blank"><span style='color:purple'>llvm@inglorion.net</span></a>> wrote:<o:p></o:p></p></div></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><div><div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana",sans-serif'>Hi Adam,</span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana",sans-serif'> </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana",sans-serif'>Thank you for writing opt-viewer! I've been playing around with it and found it helps me understand what optimizations were performed, which were missed, and why, as well as easily navigate to the relevant code. Wanting to use it on larger projects, I found that it can take a while to analyze the optimization reports. Since there doesn't seem to be too much code in it yet, I figured it wouldn't be too much work to implement the same functionality in C++, which should give us a nice speedup compared to the current Python implementation. I have something that implements most of the functionality: the index page is generated and links to lines on source pages, which are also generated, but I haven't gotten to annotations on source pages yet. I expect to put up some code for review next week, but wanted to post here in case others are thinking along similar lines so we can hopefully avoid duplicating effort.</span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana",sans-serif'><br>Cheers,</span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana",sans-serif'> </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Verdana",sans-serif'>Bob</span><o:p></o:p></p></div></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></blockquote></div></div></blockquote></div></div></div></blockquote></div></div></div></div></div></div></blockquote></div><p class=MsoNormal><o:p> </o:p></p></div></div></div></div></body></html>