From 1db19a2dbd7a8b981b2611359b6bf4547ea678f5 Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Tue, 11 Jun 2024 14:06:51 +0100 Subject: [PATCH] Remove unneeded loop through size_pools This function loops twice through the array of size pools. Once to set up the pages list, and then again later on in the function to set the allocatable_pages count. We don't do anything with the size pools in between the invocation of these loops that will affect the size pools, so this commit removes the second loop and moves the allocatable_pages count update into the first loop. --- gc.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/gc.c b/gc.c index 17136e8d23..594c0f5631 100644 --- a/gc.c +++ b/gc.c @@ -3527,6 +3527,11 @@ rb_gc_impl_objspace_alloc(void) rb_bug("Could not preregister postponed job for GC"); } + // TODO: debug why on Windows Ruby crashes on boot when GC is on. +#ifdef _WIN32 + dont_gc_on(); +#endif + for (int i = 0; i < SIZE_POOL_COUNT; i++) { rb_size_pool_t *size_pool = &size_pools[i]; @@ -3534,15 +3539,14 @@ rb_gc_impl_objspace_alloc(void) ccan_list_head_init(&SIZE_POOL_EDEN_HEAP(size_pool)->pages); ccan_list_head_init(&SIZE_POOL_TOMB_HEAP(size_pool)->pages); + + gc_params.size_pool_init_slots[i] = GC_HEAP_INIT_SLOTS; + + size_pool->allocatable_pages = minimum_pages_for_size_pool(objspace, size_pool); } rb_darray_make(&objspace->weak_references, 0); - // TODO: debug why on Windows Ruby crashes on boot when GC is on. -#ifdef _WIN32 - dont_gc_on(); -#endif - #if defined(INIT_HEAP_PAGE_ALLOC_USE_MMAP) /* Need to determine if we can use mmap at runtime. */ heap_page_alloc_use_mmap = INIT_HEAP_PAGE_ALLOC_USE_MMAP; @@ -3556,15 +3560,6 @@ rb_gc_impl_objspace_alloc(void) objspace->rgengc.oldmalloc_increase_limit = gc_params.oldmalloc_limit_min; #endif - /* Set size pools allocatable pages. */ - for (int i = 0; i < SIZE_POOL_COUNT; i++) { - rb_size_pool_t *size_pool = &size_pools[i]; - - /* Set the default value of size_pool_init_slots. */ - gc_params.size_pool_init_slots[i] = GC_HEAP_INIT_SLOTS; - - size_pool->allocatable_pages = minimum_pages_for_size_pool(objspace, size_pool); - } heap_pages_expand_sorted(objspace); init_mark_stack(&objspace->mark_stack);