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

ruby-changes:73444

From: Takashi <ko1@a...>
Date: Tue, 6 Sep 2022 15:51:30 +0900 (JST)
Subject: [ruby-changes:73444] 341b40bd0c (master): Cache RubyVM::MJIT constants

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

From 341b40bd0c2228a7759852b82af1fb11c15751e6 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Tue, 6 Sep 2022 12:57:24 +0900
Subject: Cache RubyVM::MJIT constants

for performance
---
 mjit.c          |  7 +++++++
 mjit_compiler.c | 12 ++++--------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/mjit.c b/mjit.c
index efb40216f5..6318407996 100644
--- a/mjit.c
+++ b/mjit.c
@@ -1804,6 +1804,11 @@ const struct ruby_opt_message mjit_option_messages[] = { https://github.com/ruby/ruby/blob/trunk/mjit.c#L1804
 };
 #undef M
 
+// RubyVM::MJIT::Compiler
+VALUE rb_mMJITCompiler = 0;
+// RubyVM::MJIT::C
+VALUE rb_mMJITC = 0;
+
 // Initialize MJIT.  Start a thread creating the precompiled header and
 // processing ISeqs.  The function should be called first for using MJIT.
 // If everything is successful, MJIT_INIT_P will be TRUE.
@@ -1820,6 +1825,8 @@ mjit_init(const struct mjit_options *opts) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1825
         mjit_enabled = false;
         return;
     }
+    rb_mMJITCompiler = rb_const_get(rb_mMJIT, rb_intern("Compiler"));
+    rb_mMJITC = rb_const_get(rb_mMJIT, rb_intern("C"));
 
     mjit_call_p = true;
     mjit_pid = getpid();
diff --git a/mjit_compiler.c b/mjit_compiler.c
index fccd6cfd2a..5163bbcf6b 100644
--- a/mjit_compiler.c
+++ b/mjit_compiler.c
@@ -36,10 +36,8 @@ struct case_dispatch_var { https://github.com/ruby/ruby/blob/trunk/mjit_compiler.c#L36
 static VALUE
 rb_ptr(const char *type, const void *ptr)
 {
-    // TODO: cache constant
-    VALUE rb_mMJIT = rb_const_get(rb_cRubyVM, rb_intern("MJIT"));
-    VALUE rb_mC = rb_const_get(rb_mMJIT, rb_intern("C"));
-    VALUE rb_type = rb_funcall(rb_mC, rb_intern(type), 0);
+    extern VALUE rb_mMJITC;
+    VALUE rb_type = rb_funcall(rb_mMJITC, rb_intern(type), 0);
     return rb_funcall(rb_type, rb_intern("new"), 1, ULONG2NUM((size_t)ptr));
 }
 
@@ -124,10 +122,8 @@ mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id) https://github.com/ruby/ruby/blob/trunk/mjit_compiler.c#L122
     bool original_call_p = mjit_call_p;
     mjit_call_p = false; // Avoid impacting JIT metrics by itself
 
-    // TODO: initialize the constant in mjit_init and use it
-    VALUE rb_mMJIT = rb_const_get(rb_cRubyVM, rb_intern("MJIT"));
-    VALUE rb_mCompiler = rb_const_get(rb_mMJIT, rb_intern("Compiler"));
-    bool success = RTEST(rb_funcall(rb_mCompiler, rb_intern("compile"), 4,
+    extern VALUE rb_mMJITCompiler;
+    bool success = RTEST(rb_funcall(rb_mMJITCompiler, rb_intern("compile"), 4,
                 PTR2NUM((VALUE)f), rb_ptr("rb_iseq_t", iseq), rb_str_new_cstr(funcname), INT2NUM(id)));
 
     mjit_call_p = original_call_p;
-- 
cgit v1.2.1


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

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