diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-04 14:20:17 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-04 14:25:08 +0400 |
commit | 7cb90a611faa506d7576f1f27f42be6936a45f5e (patch) | |
tree | c1147787d4e8b439a208f58fe665f1490bf5f317 /source | |
parent | 896725e0bbd77c3203ae3edcb88a032d191ef220 (diff) |
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.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 6 |
1 files changed, 5 insertions, 1 deletions
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) |