From 37e6c83609ac9d4c30ca4660ee16701e53cf82a3 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 22 Jul 2020 17:27:03 -0400 Subject: Lazily insert origins on prepend to save memory 98286e9850936e27e8ae5e4f20858cc9c13d2dde made it so that `Module#include` allocates an origin iclass on each use. Since `include` is widely used, the extra allocation can contribute significantly to memory usage. Instead of always allocating in anticipation of prepend, this change takes a different approach. The new setup inserts a origin iclass into the super chains of all the children of the module when prepend happens for the first time. rb_ensure_origin is made static again since now that adding an origin now means walking over all usages, we want to limit the number of places where we do it. --- eval.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 52f3cc4e9f..237d9acaa7 100644 --- a/eval.c +++ b/eval.c @@ -1551,9 +1551,6 @@ rb_mod_refine(VALUE module, VALUE klass) } ensure_class_or_module(klass); - if (RB_TYPE_P(klass, T_MODULE)) { - rb_ensure_origin(klass); - } CONST_ID(id_refinements, "__refinements__"); refinements = rb_attr_get(module, id_refinements); if (NIL_P(refinements)) { -- cgit v1.2.3