summaryrefslogtreecommitdiff
path: root/method.h
diff options
context:
space:
mode:
authoralpaca-tc <[email protected]>2025-04-06 01:50:08 +0900
committerKoichi Sasada <[email protected]>2025-06-09 12:33:35 +0900
commitc8ddc0a843074811b200673a2019fbe4b50bb890 (patch)
treef3881cd1f408f10abfdd7a8258d88cf18a557717 /method.h
parentd0b5f3155406e8243b78e4cedd3a38710c7c323c (diff)
Optimize callcache invalidation for refinements
Fixes [Bug #21201] This change addresses a performance regression where defining methods inside `refine` blocks caused severe slowdowns. The issue was due to `rb_clear_all_refinement_method_cache()` triggering a full object space scan via `rb_objspace_each_objects` to find and invalidate affected callcaches, which is very inefficient. To fix this, I introduce `vm->cc_refinement_table` to track callcaches related to refinements. This allows us to invalidate only the necessary callcaches without scanning the entire heap, resulting in significant performance improvement.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13077
Diffstat (limited to 'method.h')
-rw-r--r--method.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/method.h b/method.h
index b2ac07fc83..6abf2495b0 100644
--- a/method.h
+++ b/method.h
@@ -254,6 +254,9 @@ void rb_scope_visibility_set(rb_method_visibility_t);
VALUE rb_unnamed_parameters(int arity);
+void rb_vm_insert_cc_refinement(const struct rb_callcache *cc);
+void rb_vm_delete_cc_refinement(const struct rb_callcache *cc);
+
void rb_clear_method_cache(VALUE klass_or_module, ID mid);
void rb_clear_all_refinement_method_cache(void);
void rb_invalidate_method_caches(struct rb_id_table *cm_tbl, struct rb_id_table *cc_tbl);