Giovanni Mascellani (@giomasce) commented about libs/vkd3d/resource.c:
i = (i + 1) & HEAD_INDEX_MASK;
- rebalance = cache->rebalance;
- vkd3d_mutex_lock(&rebalance->mutex);
- if (rebalance->count)
- {
assert(rebalance->count >= REBALANCE_SIZE);
rebalance->count -= REBALANCE_SIZE;
vkd3d_array_reserve((void **)&cache->data, &cache->capacity, REBALANCE_SIZE, sizeof(*cache->data));
memcpy(cache->data, &rebalance->data[rebalance->count], REBALANCE_SIZE * sizeof(*cache->data));
cache->count = REBALANCE_SIZE - 1;
object = cache->data[REBALANCE_SIZE - 1];
- }
- else
- {
object = vkd3d_malloc(cache->size);
Given that you already have a thread-local cache, maybe it makes sense to allocate more than a single object each time you need one?