From 520ab22725124ef3d588c9ec664b1adfc98da905 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sun, 2 Jun 2024 23:40:24 -0700 Subject: [PATCH] Avoid unnecessary writes to imemo_env during GC Similar to the previous commit, to avoid unnecessary Copy-on-Write memory use we should only set this flag when it has not previously been set. --- imemo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imemo.c b/imemo.c index 1face1ce4e..23a9a7531f 100644 --- a/imemo.c +++ b/imemo.c @@ -357,7 +357,9 @@ rb_imemo_mark_and_move(VALUE obj, bool reference_updating) ((VALUE *)env->ep)[VM_ENV_DATA_INDEX_ENV] = rb_gc_location(env->ep[VM_ENV_DATA_INDEX_ENV]); } else { - VM_ENV_FLAGS_SET(env->ep, VM_ENV_FLAG_WB_REQUIRED); + if (!VM_ENV_FLAGS(env->ep, VM_ENV_FLAG_WB_REQUIRED)) { + VM_ENV_FLAGS_SET(env->ep, VM_ENV_FLAG_WB_REQUIRED); + } rb_gc_mark_movable( (VALUE)rb_vm_env_prev_env(env)); } }