Commit a2e51e4f authored by Kevin Modzelewski's avatar Kevin Modzelewski

Use a __thread cache for the GC's thread-local ThreadBlockCache

__thread seems quite a bit faster than pthread_get_specific, so
if we give up on having multiple Heap objects, then we can store
a reference to the current thread's ThreadBlockCache in a static
__thread variable.  It looks like this ends up mattering (5% average
speedup) since SmallArena::_alloc() is so hot
parent 243781f7
......@@ -463,7 +463,9 @@ GCAllocation* SmallArena::_alloc(size_t rounded_size, int bucket_idx) {
Block** free_head = &heads[bucket_idx];
Block** full_head = &full_heads[bucket_idx];
ThreadBlockCache* cache = thread_caches.get();
static __thread ThreadBlockCache* cache = NULL;
if (!cache)
cache = thread_caches.get();
Block** cache_head = &cache->cache_free_heads[bucket_idx];
......
......@@ -110,7 +110,14 @@ static constexpr size_t NUM_BUCKETS = sizeof(sizes) / sizeof(sizes[0]);
class SmallArena : public Arena<SMALL_ARENA_START, ARENA_SIZE> {
public:
SmallArena(Heap* heap) : Arena(), heap(heap), thread_caches(heap, this) {}
SmallArena(Heap* heap) : Arena(), heap(heap), thread_caches(heap, this) {
#ifndef NDEBUG
// Various things will crash if we instantiate multiple Heaps/Arenas
static bool already_created = false;
assert(!already_created);
already_created = true;
#endif
}
GCAllocation* __attribute__((__malloc__)) alloc(size_t bytes);
GCAllocation* realloc(GCAllocation* alloc, size_t bytes);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment