[PATCH] D20933: Preallocate ExplodedNode hash table

Ben Craig via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 3 06:23:57 PDT 2016


bcraig added a comment.

In http://reviews.llvm.org/D20933#447608, @zaks.anna wrote:

> Does FoldingSet already have reserve? (I do not see it.)


The reserve call would be new.  I'm attempting to add it in this llvm review: http://reviews.llvm.org/D20930

> My understanding is that you propose to allocate all the nodes that would be required to store the maximum number of nodes we allow, lowering the malloc traffic. The current implementation just doubles the size. Is this correct?

> 

> Maybe we should just set a higher initial size, instead of going all the way to the max?


The implementation of FoldingSet has a vector of bucket pointers.  Reserve preallocates that vector of bucket pointers to the correct size to avoid rehashing.  The allocation of the nodes themselves hasn't changed.  With a value of 150,000 steps (the default?), reserve will preallocate 131072 bucket pointers (this gives a node capacity of double that).  On a 64-bit system, that's a 1 MB allocation.

Note that the biggest savings are in avoiding the last rehashing.  If we shrink the initial size, but still rehash frequently, we'll lose a lot of the benefits.


http://reviews.llvm.org/D20933





More information about the cfe-commits mailing list