<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">-- </div><div class="">Mehdi</div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 4, 2016, at 12:18 PM, Daniel Berlin <<a href="mailto:dberlin@dberlin.org" class="">dberlin@dberlin.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Is there a patch you have handy that outputted this, so i can play around with this a bit?<div class="">Most of these hit rates seem ... really bad</div><div class=""><br class=""></div><div class="">For example, just staring at constantarrays for a second, we hash the *entire* object's operands to discover ... that they never match.</div><div class=""><br class=""></div><div class="">So that's 7204 pointless hash computations, each of which walked the entire constantarray.</div><div class=""><br class=""></div><div class="">For an array like this, a trie of any variant would discover the mismatch at the soonest opportunity (IE the hash computation is basically the lookup), and probably be significantly more memory efficient (no purpose to having a key that is not actually the array).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Plus, for fun, it would be ordered, which probably makes it easier for linkers to do prefix or tail merging optimizations.</div><div class=""><br class=""></div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Feb 4, 2016 at 11:33 AM, Mehdi Amini <span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Feb 3, 2016, at 11:33 PM, Daniel Berlin <<a href="mailto:dberlin@dberlin.org" target="_blank" class="">dberlin@dberlin.org</a>> wrote:</div><br class=""><div class=""><br class=""><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">On Wed, Feb 3, 2016 at 1:18 PM, Mehdi Amini<span class=""> </span><span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Jan 26, 2016, at 3:59 PM, Daniel Berlin <<a href="mailto:dberlin@dberlin.org" target="_blank" class="">dberlin@dberlin.org</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Jan 26, 2016 at 3:35 PM, Mehdi Amini<span class=""> </span><span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word" class="">The hash should (almost?) never change.<div class="">I thought about this solution, and I plan on evaluating it a well (it applies to constants as well). </div><div class="">However there is a tradeoff of memory vs speed doing this.</div><div class="">For instance when doing LTO, we load a lot of metadata when loading and linking individual Modules, which put a lot of stress on the hash tables (both uniquing and grow). But then during optimization and CodeGen it shouldn’t and I’m not sure we want to pay the price of the memory overhead then.</div><div class=""><br class=""></div></div></blockquote><div class="">This naturally raises the questions of whether you really need hash tables to get what you want, or would some other more memory-efficient data structure be better for uniquing :)</div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">I think this is a great point.</div><span class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">While DenseMap is pretty good,  you do end up with a lot of empty buckets (or pay a high probing price).<br class=""></div><div class=""><br class=""></div><div class="">Whereas, depending on the situation and structure, you can often pay a much lower cost (and have better behavior on hash misses). Obviously, in most cases, DenseMap should be the choice because it's consistent and who cares, but in specific situations if you are placing huge stress on it during say, uniquing, there are often better ways both in time and space (various compressed tries, ternary search trees, etc).</div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">Debug Info metadata are putting a lot of stress both on CPU time as it shows up on the profile quite frequently, and on the memory (even it is far better now than in the past following all the work driven by Duncan last year).</div><div class="">An LTO build of llvm-tblgen consumes at peak 130MB without debug info, and 740MB with debug info. Since you’re familiar with GCC are you aware of the </div><div class=""><br class=""></div></div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div><div class="">A sentence got lost here :)</div></div></div></blockquote><div class=""><br class=""></div></span><div class="">Indeed :)</div><div class="">This is what happens when you start an email and come back to it a few days ago thinking it was sent…</div><div class=""><br class=""></div><div class="">I was wondering what the memory consumption ratio with/without debug info for C++ in GCC (or ICC, or [insert your other C++ compiler here]).</div><span class=""><div class=""><br class=""></div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class=""><br class=""></div><div class="">BTW, do you know the hash miss rate on the hash tables involved in uniqing?<br class=""></div><div class=""><br class=""></div><div class="">(IE how many total lookups and how many times is the thing in the hash table)</div><div class=""><br class="">If the hash hit rate is very high, more memory efficient hash tables are viable (sparse_hash_map), etc.</div><div class="">If the hash hit rate is not that high, it's likely other structures will be both faster and more efficient.</div></div></div></blockquote></span></div><br class=""><div class="">It varies depending on which one and what is the use case :) For instance reading bitcode in a fresh new context does not show any hit (as expected).</div><div class=""><br class=""></div><div class="">It seems we may want to do some specialization here...</div><div class=""><br class=""></div><div class="">I computed the full numbers for various cases: </div><div class=""><br class=""></div><div class=""> - Clang IRGen (disable LLVM Opt)</div><div class=""> - Clang O3</div><div class=""> - ThinLTO link for llvm-tblgen (which include loading multiple bitcode files in the same context, trashing the context and starting over multiple times).</div><div class=""><br class=""></div><div class="">Note:  for Constants I only counted the calls to `getOrCreate()`, and not query issued by `replaceOperandsInPlace()`.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Clang -g -O3 -disable-llvm-optzns -emit-llvm-bc  (llvm/utils/TableGen/CodeGenDAGPatterns.cpp)</div><div class=""><br class=""></div><div class="">DISubrange<span style="white-space:pre-wrap" class="">                                </span>Hit rate: 17/33 : <span style="white-space:pre-wrap" class="">           </span>51.52%<br class="">DIEnumerator<span style="white-space:pre-wrap" class="">                              </span>Hit rate: 91/285 : <span style="white-space:pre-wrap" class="">          </span>31.93%<br class="">DIBasicType<span style="white-space:pre-wrap" class="">                               </span>Hit rate: 0/17 : <span style="white-space:pre-wrap" class="">            </span>0.00%<br class="">DIDerivedType<span style="white-space:pre-wrap" class="">                      </span>Hit rate: 15066/43578 : <span style="white-space:pre-wrap" class="">     </span>34.57%<br class="">DICompositeType<span style="white-space:pre-wrap" class="">                   </span>Hit rate: 1/2734 : <span style="white-space:pre-wrap" class="">          </span>0.04%<br class="">DISubroutineType<span style="white-space:pre-wrap" class="">                   </span>Hit rate: 6415/26549 : <span style="white-space:pre-wrap" class="">      </span>24.16%<br class="">DIFile<span style="white-space:pre-wrap" class="">                                    </span>Hit rate: 1969/2064 : <span style="white-space:pre-wrap" class="">       </span>95.40%<br class="">DISubprogram<span style="white-space:pre-wrap" class="">                              </span>Hit rate: 0/18083 : <span style="white-space:pre-wrap" class="">         </span>0.00%<br class="">DILexicalBlock<span style="white-space:pre-wrap" class="">                     </span>Hit rate: 0/2392 : <span style="white-space:pre-wrap" class="">          </span>0.00%<br class="">DILexicalBlockFile<span style="white-space:pre-wrap" class="">                 </span>Hit rate: 0/0 :<br class="">DINamespace<span style="white-space:pre-wrap" class="">                              </span>Hit rate: 0/7 : <span style="white-space:pre-wrap" class="">                     </span>0.00%<br class="">DIModule<span style="white-space:pre-wrap" class="">                                   </span>Hit rate: 0/0 :<br class="">DITemplateTypeParameter<span style="white-space:pre-wrap" class="">  </span>Hit rate: 3279/5101 : <span style="white-space:pre-wrap" class="">       </span>64.28%<br class="">DITemplateValueParameter<span style="white-space:pre-wrap" class="">  </span>Hit rate: 857/923 : <span style="white-space:pre-wrap" class="">         </span>92.85%<br class="">DIGlobalVariable<span style="white-space:pre-wrap" class="">                  </span>Hit rate: 0/0 : <br class="">DILocalVariable<span style="white-space:pre-wrap" class="">                    </span>Hit rate: 0/7058 : <span style="white-space:pre-wrap" class="">          </span>0.00%<br class="">DIExpression<span style="white-space:pre-wrap" class="">                               </span>Hit rate: 7056/7058 : <span style="white-space:pre-wrap" class="">       </span>99.97%<br class="">DIImportedEntity<span style="white-space:pre-wrap" class="">                  </span>Hit rate: 0/357 : <span style="white-space:pre-wrap" class="">           </span>0.00%<br class="">DIMacro<span style="white-space:pre-wrap" class="">                                    </span>Hit rate: 0/0 : <br class="">DIMacroFile<span style="white-space:pre-wrap" class="">                                </span>Hit rate: 0/0 : <br class="">Constant InlineAsm<span style="white-space:pre-wrap" class="">         </span><span style="white-space:pre-wrap" class="">     </span>Hit rate: 0/0 : <br class="">Constant ConstantExpr<span style="white-space:pre-wrap" class="">              </span>Hit rate: 149/410 : <span style="white-space:pre-wrap" class="">         </span>36.34%<br class="">Constant ConstantVector<span style="white-space:pre-wrap" class="">      </span>Hit rate: 0/0 : <br class="">Constant ConstantStruct<span style="white-space:pre-wrap" class="">               </span>Hit rate: 0/0 : <br class="">Constant ConstantArray<span style="white-space:pre-wrap" class="">                </span>Hit rate: 0/0 : </div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">Clang -g -O3  -emit-obj   -emit-llvm-bc  (llvm/utils/TableGen/CodeGenDAGPatterns.cpp)</div></div><div class=""><br class=""></div><div class="">DISubrange<span style="white-space:pre-wrap" class="">                             </span>Hit rate: 17/33 : <span style="white-space:pre-wrap" class="">           </span>51.52%<br class="">DIEnumerator<span style="white-space:pre-wrap" class="">                              </span>Hit rate: 91/285 : <span style="white-space:pre-wrap" class="">          </span>31.93%<br class="">DIBasicType<span style="white-space:pre-wrap" class="">                               </span>Hit rate: 0/17 : <span style="white-space:pre-wrap" class="">            </span>0.00%<br class="">DIDerivedType<span style="white-space:pre-wrap" class="">                      </span>Hit rate: 15066/43578 : <span style="white-space:pre-wrap" class="">     </span>34.57%<br class="">DICompositeType<span style="white-space:pre-wrap" class="">                   </span>Hit rate: 1/2734 : <span style="white-space:pre-wrap" class="">          </span>0.04%<br class="">DISubroutineType<span style="white-space:pre-wrap" class="">                   </span>Hit rate: 6415/26549 : <span style="white-space:pre-wrap" class="">      </span>24.16%<br class="">DIFile<span style="white-space:pre-wrap" class="">                                    </span>Hit rate: 1969/2064 : <span style="white-space:pre-wrap" class="">       </span>95.40%<br class="">DISubprogram<span style="white-space:pre-wrap" class="">                              </span>Hit rate: 0/18083 : <span style="white-space:pre-wrap" class="">         </span>0.00%<br class="">DILexicalBlock<span style="white-space:pre-wrap" class="">                     </span>Hit rate: 0/2392 : <span style="white-space:pre-wrap" class="">          </span>0.00%<br class="">DILexicalBlockFile<span style="white-space:pre-wrap" class="">                 </span>Hit rate: 0/0<br class="">DINamespace<span style="white-space:pre-wrap" class="">                                </span>Hit rate: 0/7 :<span style="white-space:pre-wrap" class="">                      </span>0.00%<br class="">DIModule<span style="white-space:pre-wrap" class="">                                   </span>Hit rate: 0/0<br class="">DITemplateTypeParameter<span style="white-space:pre-wrap" class="">    </span>Hit rate: 3279/5101 : <span style="white-space:pre-wrap" class="">       </span>64.28%<br class="">DITemplateValueParameter<span style="white-space:pre-wrap" class="">  </span>Hit rate: 857/923 : <span style="white-space:pre-wrap" class="">         </span>92.85%<br class="">DIGlobalVariable<span style="white-space:pre-wrap" class="">                  </span>Hit rate: 0/0<br class="">DILocalVariable<span style="white-space:pre-wrap" class="">                    </span>Hit rate: 0/7058 :<span style="white-space:pre-wrap" class="">   </span> <span style="white-space:pre-wrap" class="">    </span>0.00%<br class="">DIExpression<span style="white-space:pre-wrap" class="">                               </span>Hit rate: 8415/8427 : <span style="white-space:pre-wrap" class="">       </span>99.86%<br class="">DIImportedEntity<span style="white-space:pre-wrap" class="">                  </span>Hit rate: 0/357 : <span style="white-space:pre-wrap" class="">           </span>0.00%<br class="">DIMacro<span style="white-space:pre-wrap" class="">                                    </span>Hit rate: 0/0<br class="">DIMacroFile<span style="white-space:pre-wrap" class="">                                </span>Hit rate: 0/0<br class="">Constant InlineAsm<span style="white-space:pre-wrap" class="">                    </span>Hit rate: 0/0<br class="">Constant ConstantExpr<span style="white-space:pre-wrap" class="">         </span>Hit rate: 7475/8067 : <span style="white-space:pre-wrap" class="">       </span>92.66%<br class="">Constant ConstantVector<span style="white-space:pre-wrap" class="">      </span>Hit rate: 26/28 : <span style="white-space:pre-wrap" class="">           </span>92.86%<br class="">Constant ConstantStruct<span style="white-space:pre-wrap" class="">              </span>Hit rate: 0/0<br class="">Constant ConstantArray<span style="white-space:pre-wrap" class="">                </span>Hit rate: 0/0</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">ThinLTO linking of llvm-tblgen:</div><div class=""><br class=""></div><div class="">DISubrange<span style="white-space:pre-wrap" class="">                              </span>Hit rate: 4949/7031 : <span style="white-space:pre-wrap" class="">               </span>70.39%</div><div class="">DIEnumerator<span style="white-space:pre-wrap" class="">                         </span>Hit rate: 43375/61459 : <span style="white-space:pre-wrap" class="">             </span>70.58%<br class="">DIBasicType<span style="white-space:pre-wrap" class="">                               </span>Hit rate: 9942/12652 : <span style="white-space:pre-wrap" class="">              </span>78.58%<br class="">DIDerivedType<span style="white-space:pre-wrap" class="">                     </span>Hit rate: 1604694/3023073 : <span style="white-space:pre-wrap" class=""> </span>53.08%<br class="">DICompositeType<span style="white-space:pre-wrap" class="">                   </span>Hit rate: 293974/582982 : <span style="white-space:pre-wrap" class="">   </span>50.43%<br class="">DISubroutineType<span style="white-space:pre-wrap" class="">                  </span>Hit rate: 1478051/2689262 : <span style="white-space:pre-wrap" class=""> </span>54.96%<br class="">DIFile<span style="white-space:pre-wrap" class="">                                    </span>Hit rate: 36599/50437 : <span style="white-space:pre-wrap" class="">             </span>72.56%<br class="">DISubprogram<span style="white-space:pre-wrap" class="">                              </span>Hit rate: 1997375/4135969 : <span style="white-space:pre-wrap" class=""> </span>48.29%<br class="">DILexicalBlock<span style="white-space:pre-wrap" class="">                    </span>Hit rate: 0/293545 : <span style="white-space:pre-wrap" class="">                        </span>0.00%<br class="">DILexicalBlockFile<span style="white-space:pre-wrap" class="">                 </span>Hit rate: 0/8 : <span style="white-space:pre-wrap" class="">                             </span>0.00%<br class="">DINamespace<span style="white-space:pre-wrap" class="">                                </span>Hit rate: 2597/5112 : <span style="white-space:pre-wrap" class="">               </span>50.80%<br class="">DIModule<span style="white-space:pre-wrap" class="">                                  </span>Hit rate: 0/0<br class="">DITemplateTypeParameter<span style="white-space:pre-wrap" class="">    </span>Hit rate: 180597/366500 : <span style="white-space:pre-wrap" class="">   </span>49.28%<br class="">DITemplateValueParameter<span style="white-space:pre-wrap" class="">  </span>Hit rate: 13800/25549 : <span style="white-space:pre-wrap" class="">             </span>54.01%<br class="">DIGlobalVariable<span style="white-space:pre-wrap" class="">                  </span>Hit rate: 8/2910 : <span style="white-space:pre-wrap" class="">                  </span>0.27%<br class="">DILocalVariable<span style="white-space:pre-wrap" class="">                    </span>Hit rate: 0/1315871 : <span style="white-space:pre-wrap" class="">               </span>0.00%<br class="">DIExpression<span style="white-space:pre-wrap" class="">                               </span>Hit rate: 10323/11069 : <span style="white-space:pre-wrap" class="">             </span>93.26%<br class="">DIImportedEntity<span style="white-space:pre-wrap" class="">                  </span>Hit rate: 200237/230868 : <span style="white-space:pre-wrap" class="">   </span>86.73%<br class="">DIMacro<span style="white-space:pre-wrap" class="">                                   </span>Hit rate: 0/0<br class="">DIMacroFile<span style="white-space:pre-wrap" class="">                                </span>Hit rate: 0/0<br class="">Constant InlineAsm<span style="white-space:pre-wrap" class="">                    </span>Hit rate: 0/0<br class=""><div class="">Constant ConstantExpr<span style="white-space:pre-wrap" class="">           </span>Hit rate: 239332/290443 : <span style="white-space:pre-wrap" class="">   </span>82.40%<br class="">Constant ConstantVector<span style="white-space:pre-wrap" class="">      </span>Hit rate: 0/3 : <span style="white-space:pre-wrap" class="">                             </span>0.00%<br class="">Constant ConstantStruct<span style="white-space:pre-wrap" class="">               </span>Hit rate: 926/4360 : <span style="white-space:pre-wrap" class="">                </span>21.24%<br class="">Constant ConstantArray<span style="white-space:pre-wrap" class="">               </span>Hit rate: 16/7220 : <span style="white-space:pre-wrap" class="">                 </span>0.22%</div><br class=""></div><div class=""><br class=""></div><div class="">— </div><span class="HOEnZb"><font color="#888888" class=""><div class="">Mehdi</div><div class=""><br class=""></div></font></span></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>