From 9162ec83a83cc42c9c2ba4a6528d6d56c8feb4da Mon Sep 17 00:00:00 2001 From: Kiran Pamnany Date: Fri, 8 Nov 2024 14:06:58 -0500 Subject: [PATCH] Only update the world age when a new method is loaded (#196) Instead of always updating it. This should speed up loading only method specializations. --- src/staticdata.c | 12 ++++++++++-- src/staticdata_utils.c | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/staticdata.c b/src/staticdata.c index 945593034a890..fba0eb95c9ae1 100644 --- a/src/staticdata.c +++ b/src/staticdata.c @@ -2952,7 +2952,6 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl jl_set_gs_ctr(gs_ctr); } else { - jl_atomic_fetch_add(&jl_world_counter, 1); offset_restored = jl_read_offset(&s); offset_init_order = jl_read_offset(&s); offset_extext_methods = jl_read_offset(&s); @@ -3182,7 +3181,6 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl jl_cache_type_((jl_datatype_t*)obj); } // Perform fixups: things like updating world ages, inserting methods & specializations, etc. - size_t world = jl_atomic_load_acquire(&jl_world_counter); for (size_t i = 0; i < s.uniquing_objs.len; i++) { uintptr_t item = (uintptr_t)s.uniquing_objs.items[i]; // check whether this is a gvar index @@ -3236,6 +3234,16 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl o->bits.in_image = 1; } arraylist_free(&cleanup_list); + size_t world = jl_atomic_load_relaxed(&jl_world_counter); + for (size_t i = 0; i < s.fixup_objs.len; i++) { + // decide if we need to allocate a world + uintptr_t item = (uintptr_t)s.fixup_objs.items[i]; + jl_value_t *obj = (jl_value_t*)(image_base + item); + if (jl_is_method(obj)) { + world = jl_atomic_fetch_add(&jl_world_counter, 1) + 1; + break; + } + } for (size_t i = 0; i < s.fixup_objs.len; i++) { uintptr_t item = (uintptr_t)s.fixup_objs.items[i]; jl_value_t *obj = (jl_value_t*)(image_base + item); diff --git a/src/staticdata_utils.c b/src/staticdata_utils.c index 2fe01d919e885..807fa2196ddf7 100644 --- a/src/staticdata_utils.c +++ b/src/staticdata_utils.c @@ -840,6 +840,10 @@ static jl_array_t *jl_verify_edges(jl_array_t *targets, size_t minworld) if (ulong_array == NULL) ulong_array = jl_apply_array_type((jl_value_t*)jl_ulong_type, 1); jl_array_t *maxvalids = jl_alloc_array_1d(ulong_array, l); + if (minworld == jl_base_module->primary_world) { + memset(jl_array_data(maxvalids), -1, l * sizeof(size_t)); + return maxvalids; + } memset(jl_array_data(maxvalids), 0, l * sizeof(size_t)); jl_value_t *loctag = NULL; jl_value_t *matches = NULL;