From e6a145eeac8e049210af7d1672151b6322d089d0 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 11 Jan 2017 18:03:13 +0000 Subject: [PATCH] Potential speedup? Attempt to speed up gc_collector_mark_gray by forcing it to be inlined via a C macro. I am skeptical the compiler cannot do this already but the change seems to speed the earley benchmark up by several seconds. --- gc.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/gc.c b/gc.c index 075a11e9..b04a8aef 100644 --- a/gc.c +++ b/gc.c @@ -1183,21 +1183,28 @@ void gc_collector_trace() } } -static void gc_collector_mark_gray(object parent, object obj) -{ - // "Color" objects gray by adding them to the mark stack for further processing. - // - // Note that stack objects are always colored red during creation, so - // they should never be added to the mark stack. Which would be bad because it - // could lead to stack corruption. - if (is_object_type(obj) && mark(obj) == gc_color_clear) { - mark_stack = vpbuffer_add(mark_stack, &mark_stack_len, mark_stack_i++, obj); -#if GC_DEBUG_VERBOSE - fprintf(stderr, "mark gray parent = %p (%d) obj = %p\n", parent, - type_of(parent), obj); -#endif +// "Color" objects gray by adding them to the mark stack for further processing. +// +// Note that stack objects are always colored red during creation, so +// they should never be added to the mark stack. Which would be bad because it +// could lead to stack corruption. +// +// Attempt to speed this up by forcing an inline +// +#define gc_collector_mark_gray(parent, gobj) \ + if (is_object_type(gobj) && mark(gobj) == gc_color_clear) { \ + mark_stack = vpbuffer_add(mark_stack, &mark_stack_len, mark_stack_i++, gobj); \ } -} +//static void gc_collector_mark_gray(object parent, object obj) +//{ +// if (is_object_type(obj) && mark(obj) == gc_color_clear) { +// mark_stack = vpbuffer_add(mark_stack, &mark_stack_len, mark_stack_i++, obj); +//#if GC_DEBUG_VERBOSE +// fprintf(stderr, "mark gray parent = %p (%d) obj = %p\n", parent, +// type_of(parent), obj); +//#endif +// } +//} // TODO: seriously consider changing the mark() macro to color(), // and sync up the header variable. that would make all of this code