From 7cb90a611faa506d7576f1f27f42be6936a45f5e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 4 Apr 2014 21:20:17 +1100 Subject: Optimization for mempool initial chunk allocation Almost all pools allocated 2 chunks on initialization, every element needed to be added to the free-list which would never be used for small pools. Now allocate only one, gives minor speedup for some bmesh operations. --- source/blender/blenlib/intern/BLI_mempool.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source/blender/blenlib/intern/BLI_mempool.c') diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 7dc43bb1494..a37a7781286 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -121,10 +121,14 @@ struct BLI_mempool { /** * \return the number of chunks to allocate based on how many elements are needed. + * + * \note for small pools 1 is a good default, the elements need to be initialized, + * adding overhead on creation which is redundant if they aren't used. + * */ BLI_INLINE unsigned int mempool_maxchunks(const unsigned int totelem, const unsigned int pchunk) { - return totelem / pchunk + 1; + return (totelem <= pchunk) ? 1 : ((totelem / pchunk) + 1); } static BLI_mempool_chunk *mempool_chunk_alloc(BLI_mempool *pool) -- cgit v1.2.3