[前][次][番号順一覧][スレッド一覧]

ruby-changes:74127

From: Aaron <ko1@a...>
Date: Wed, 19 Oct 2022 23:55:16 +0900 (JST)
Subject: [ruby-changes:74127] eeea633eb2 (master): Stop zeroing memory on allocation / copy

https://git.ruby-lang.org/ruby.git/commit/?id=eeea633eb2

From eeea633eb20cfdcaf0fec35109afa3821cb994f3 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Tue, 27 Sep 2022 11:51:34 -0700
Subject: Stop zeroing memory on allocation / copy

Shapes gives us an almost exact count of instance variables on an
object.  Since we know the number of instance variables that have been
set, we will never access slots that haven't been initialized with an
IV.
---
 gc.c       | 33 ++++++++-------------------------
 variable.c |  3 ---
 2 files changed, 8 insertions(+), 28 deletions(-)

diff --git a/gc.c b/gc.c
index ffc610dcc7..44b3f6a83c 100644
--- a/gc.c
+++ b/gc.c
@@ -2919,40 +2919,28 @@ rb_class_instance_allocate_internal(VALUE klass, VALUE flags, bool wb_protected) https://github.com/ruby/ruby/blob/trunk/gc.c#L2919
     uint32_t index_tbl_num_entries = RCLASS_EXT(klass)->max_iv_count;
 
     size_t size;
-    bool embed = true;
 #if USE_RVARGC
     size = rb_obj_embedded_size(index_tbl_num_entries);
     if (!rb_gc_size_allocatable_p(size)) {
         size = sizeof(struct RObject);
-        embed = false;
     }
 #else
     size = sizeof(struct RObject);
-    if (index_tbl_num_entries > ROBJECT_EMBED_LEN_MAX) {
-        embed = false;
-    }
 #endif
 
-#if USE_RVARGC
     VALUE obj = newobj_of(klass, flags, 0, 0, 0, wb_protected, size);
-#else
-    VALUE obj = newobj_of(klass, flags, Qundef, Qundef, Qundef, wb_protected, size);
-#endif
 
-    if (embed) {
 #if USE_RVARGC
-        uint32_t capa = (uint32_t)((rb_gc_obj_slot_size(obj) - offsetof(struct RObject, as.ary)) / sizeof(VALUE));
-        GC_ASSERT(capa >= index_tbl_num_entries);
-
-        ROBJECT(obj)->numiv = capa;
-        for (size_t i = 0; i < capa; i++) {
-            ROBJECT(obj)->as.ary[i] = Qundef;
-        }
+    uint32_t capa = (uint32_t)((rb_gc_obj_slot_size(obj) - offsetof(struct RObject, as.ary)) / sizeof(VALUE));
+    ROBJECT(obj)->numiv = capa;
 #endif
+
+#if RUBY_DEBUG
+    VALUE *ptr = ROBJECT_IVPTR(obj);
+    for (size_t i = 0; i < ROBJECT_NUMIV(obj); i++) {
+        ptr[i] = Qundef;
     }
-    else {
-        rb_ensure_iv_list_size(obj, 0, index_tbl_num_entries);
-    }
+#endif
 
     return obj;
 }
@@ -10032,11 +10020,6 @@ gc_ref_update_object(rb_objspace_t *objspace, VALUE v) https://github.com/ruby/ruby/blob/trunk/gc.c#L10020
 
         uint32_t capa = (uint32_t)((slot_size - offsetof(struct RObject, as.ary)) / sizeof(VALUE));
         ROBJECT(v)->numiv = capa;
-
-        // Fill end with Qundef
-        for (uint32_t i = numiv; i < capa; i++) {
-            ptr[i] = Qundef;
-        }
     }
 #endif
 
diff --git a/variable.c b/variable.c
index 8d329d7900..d83b8487a7 100644
--- a/variable.c
+++ b/variable.c
@@ -1404,9 +1404,6 @@ rb_ensure_iv_list_size(VALUE obj, uint32_t len, uint32_t newsize) https://github.com/ruby/ruby/blob/trunk/variable.c#L1404
         newptr = obj_ivar_heap_realloc(obj, len, newsize);
     }
 
-    for (; len < newsize; len++) {
-        newptr[len] = Qundef;
-    }
 #if USE_RVARGC
     ROBJECT(obj)->numiv = newsize;
 #else
-- 
cgit v1.2.3


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]