From dfd29cab1f3d3916f02a32aaafb1d2ac091b89b3 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sun, 2 Jun 2024 23:39:36 -0700 Subject: [PATCH] Avoid unnecessary writes to ISEQ during GC On mark we check whether a callcache has been invalidated and if it has we replace it with the empty callcache, rb_vm_empty_cc(). However we also consider the empty callcache to not be active, and so previously would overwrite it with itself. These additional writes are problematic because they may force Copy-on-Write to occur on the memory page, increasing system memory use. --- iseq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iseq.c b/iseq.c index 27c5bb5d82d907..e8cafd6caa02a1 100644 --- a/iseq.c +++ b/iseq.c @@ -344,7 +344,7 @@ rb_iseq_mark_and_move(rb_iseq_t *iseq, bool reference_updating) if (cc_is_active(cds[i].cc, reference_updating)) { rb_gc_mark_and_move_ptr(&cds[i].cc); } - else { + else if (cds[i].cc != rb_vm_empty_cc()) { cds[i].cc = rb_vm_empty_cc(); } }