Skip to content

Commit 5001c19

Browse files
Compress the size_to_heap_idx table
Index on 8 byte chunks instead of individual bytes. This works because all pool stot sizes are pointer aligned, so all sizes in an 8 byte range map to the same heap.
1 parent 208b173 commit 5001c19

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

gc/default/default.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ static const size_t pool_slot_sizes[HEAP_COUNT] = {
697697
RVALUE_SLOT_SIZE * 16,
698698
};
699699

700-
static uint8_t size_to_heap_idx[RVALUE_SLOT_SIZE * (1 << (HEAP_COUNT - 1)) + 1];
700+
static uint8_t size_to_heap_idx[RVALUE_SLOT_SIZE * (1 << (HEAP_COUNT - 1)) / 8 + 1];
701701

702702
#ifndef MAX
703703
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
@@ -2355,23 +2355,22 @@ ractor_cache_set_page(rb_objspace_t *objspace, rb_ractor_newobj_cache_t *cache,
23552355
static void
23562356
init_size_to_heap_idx(void)
23572357
{
2358-
GC_ASSERT(pool_slot_sizes[HEAP_COUNT - 1] - RVALUE_OVERHEAD < sizeof(size_to_heap_idx));
2359-
2360-
for (size_t size = 0; size < sizeof(size_to_heap_idx); size++) {
2361-
size_t effective = size + RVALUE_OVERHEAD;
2358+
for (size_t i = 0; i < sizeof(size_to_heap_idx); i++) {
2359+
size_t effective = i * 8 + RVALUE_OVERHEAD;
23622360
uint8_t idx;
23632361
for (idx = 0; idx < HEAP_COUNT; idx++) {
23642362
if (effective <= pool_slot_sizes[idx]) break;
23652363
}
2366-
size_to_heap_idx[size] = idx;
2364+
size_to_heap_idx[i] = idx;
23672365
}
23682366
}
23692367

23702368
static inline size_t
23712369
heap_idx_for_size(size_t size)
23722370
{
2373-
if (size < sizeof(size_to_heap_idx)) {
2374-
size_t heap_idx = size_to_heap_idx[size];
2371+
size_t compressed = (size + 7) >> 3;
2372+
if (compressed < sizeof(size_to_heap_idx)) {
2373+
size_t heap_idx = size_to_heap_idx[compressed];
23752374
if (RB_LIKELY(heap_idx < HEAP_COUNT)) return heap_idx;
23762375
}
23772376

0 commit comments

Comments
 (0)