[PATCH] D118608: [NFC] Increase initial size of FoldingSets used in ASTContext and CodeGenTypes

Dawid Jurczak via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 3 03:31:35 PST 2022


yurai007 added a comment.

In D118608#3290086 <https://reviews.llvm.org/D118608#3290086>, @serge-sans-paille wrote:

> Thanks, that's helpful. Any hint about why this particular values?

Sure, let me elaborate on this. Initial capacities were empirically chosen to reduce number of internal hashtable growths (rehashings) in FoldingSet. 
FoldingSet has initial size set to 6 by default which corresponds to 2^6 buckets in internal hashtable. In most cases it's ok and doesn't really matter. 
However while building huge codebase (like Linux) I find PointerTypes/ElaboratedTypes/ParenTypes beeing hot and growing very often to 256 (2^8) or 512 buckets (2^9). 
That would explains choosing GeneralTypesLog2InitSize and ConstantArrayTypesLog2InitSize as more appropriate initial values.
For FunctionProtoTypes initial 2^6 capacity is way too conservative as its ContextualFoldingSet easly grows to 2^10/2^11 buckets.
It's not only about "empirical proof". For example from frontend perspective FunctionProtoTypes keeps all found function prototypes in compiling module.
Since it's reasonable to assume that average non-trivial module has rather hundreds or thousands functions than 64 using 2^12 as initial capacity should be enough.
Also it's worth to mention that with such approach we don't pay much in terms of memory footprint because FoldingSet internally in hashtable stores just pointers.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118608/new/

https://reviews.llvm.org/D118608



More information about the cfe-commits mailing list