<html><head><base href="x-msg://2320/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Feb 15, 2012, at 2:57 AM, James Molloy wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div lang="EN-GB" link="blue" vlink="purple"><div class="Section1" style="page: Section1; "><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">Hi,<o:p></o:p></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">One of PlumHall’s testcases generates a function with half a million SDNodes. This brings out the O(n) complexity in DAGCombiner::AddToWorkList() and means that in debug mode the test has not been seen to complete compilation, and in release mode it takes several hours. KCacheGrind showed 99% of the time is being spent in std::remove, doing linear scans of the DAGCombiner’s worklist during AddToWorkList.</div></div></div></span></blockquote><div><br></div>Wow, that's bad :), I'm surprised that this terrible algorithm lasted so long.</div><div><br><blockquote type="cite"><span class="Apple-style-span" style="font-family: Calibri, sans-serif; font-size: 15px; ">My solution was to allow duplicate items in the vector, and on every pop to query the set to see if the item should actually be in the vector. If not, discard and grab the next item. This means that the vector could potentially grow larger than it would previously.</span><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div lang="EN-GB" link="blue" vlink="purple"><div class="Section1" style="page: Section1; "><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p></o:p></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p></o:p></div></div></div></span></blockquote></div><font class="Apple-style-span" face="Calibri, sans-serif"><span class="Apple-style-span" style="font-size: 15px;"><br></span></font><div>The approach makes sense.  Some requests on the patch:</div><div><br></div><div>1. Please use SmallPtrSet<> instead of std::set, it will be much more efficient (and may help your timings even more).  See also: <a href="http://llvm.org/docs/ProgrammersManual.html#ds_set">http://llvm.org/docs/ProgrammersManual.html#ds_set</a></div><div><br></div><div>2. In removeFromWorkList, you can just call WorkListContents.erase(N) instead of find+erase.</div><div><br></div><div>3. You removed the comment from AddToWorkList about making sure that the thing added is next-to-be-processed.  As you discovered, this is important, please keep the comment.</div><div><br></div><div>4. The comments you added are great, but should be written explaining the algorithm your adding, not explaining a delta from the old code.  When this goes in the new algorithm will be truth, and the comments should explain why it works this way.</div><div><br></div><div>Thanks for finding and fixing this James!</div><div><br></div><div>-Chris</div></body></html>