From 51919cfdf83824006e3a66ba83c551f62d778714 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 26 Sep 2019 10:07:10 -0400 Subject: [PATCH] Speed up object mutation No need to track for minor GC purposes unless we are mutating a heap variable to point to a stack var. --- runtime.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/runtime.c b/runtime.c index d0a6aae6..911ebdff 100644 --- a/runtime.c +++ b/runtime.c @@ -477,15 +477,23 @@ void Cyc_set_globals_changed(gc_thread_data *thd) /* Mutation table functions * - * Keep track of mutations (EG: set-car!) so that new - * values are transported to the heap during GC. + * Keep track of mutations (EG: set-car!) so we can avoid having heap + * objects that point to old stack objects. We need to transport any + * such stack objects to the heap during minor GC. + * * Note these functions and underlying data structure are only used by * the calling thread, so locking is not required. */ void add_mutation(void *data, object var, int index, object value) { gc_thread_data *thd = (gc_thread_data *) data; - if (is_object_type(value)) { + + // No need to track for minor GC purposes unless we are mutating + // a heap variable to point to a stack var. + // + // If var is on stack we'll get it anyway in minor GC, + // and if value is on heap we don't care (no chance of heap pointing to nursery) + if (!gc_is_stack_obj(data, var) && gc_is_stack_obj(data, value)) { thd->mutations = vpbuffer_add(thd->mutations, &(thd->mutation_buflen), thd->mutation_count,