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

ruby-changes:62147

From: Takashi <ko1@a...>
Date: Mon, 6 Jul 2020 16:14:52 +0900 (JST)
Subject: [ruby-changes:62147] 167d139487 (master): Inline builtin struct aref

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

From 167d139487d67613bd02522e24476f06ffa137b7 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Mon, 6 Jul 2020 00:11:51 -0700
Subject: Inline builtin struct aref

We don't do this for aset because it might raise a FrozenError.

```
$ benchmark-driver -v --rbenv 'before;after;before --jit;after --jit' benchmark/mjit_struct_aref.yml --repeat-count=4
before: ruby 2.8.0dev (2020-07-06T01:47:11Z master d94ef7c6b6) [x86_64-linux]
after: ruby 2.8.0dev (2020-07-06T07:11:51Z master 85425168f4) [x86_64-linux]
last_commit=Inline builtin struct aref
before --jit: ruby 2.8.0dev (2020-07-06T01:47:11Z master d94ef7c6b6) +JIT [x86_64-linux]
after --jit: ruby 2.8.0dev (2020-07-06T07:11:51Z master 85425168f4) +JIT [x86_64-linux]
last_commit=Inline builtin struct aref
Calculating -------------------------------------
                             before       after  before --jit  after --jit
mjit_struct_aref(struct)    34.783M     34.810M       48.321M      58.378M i/s -     40.000M times in 1.149996s 1.149097s 0.827794s 0.685192s

Comparison:
             mjit_struct_aref(struct)
             after --jit:  58377836.7 i/s
            before --jit:  48321205.7 i/s - 1.21x  slower
                   after:  34809935.5 i/s - 1.68x  slower
                  before:  34782736.5 i/s - 1.68x  slower
```

diff --git a/benchmark/mjit_struct_aref.yml b/benchmark/mjit_struct_aref.yml
new file mode 100644
index 0000000..bfba132
--- /dev/null
+++ b/benchmark/mjit_struct_aref.yml
@@ -0,0 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/mjit_struct_aref.yml#L1
+type: lib/benchmark_driver/runner/mjit
+prelude: |
+  def mjit_struct_aref(struct)
+    struct.aa
+  end
+  struct = Struct.new(:a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, :aa).new
+
+benchmark: mjit_struct_aref(struct)
+
+loop_count: 40000000
diff --git a/struct.c b/struct.c
index 41349f7..9390602 100644
--- a/struct.c
+++ b/struct.c
@@ -324,6 +324,7 @@ static void https://github.com/ruby/ruby/blob/trunk/struct.c#L324
 define_aref_method(VALUE nstr, VALUE name, VALUE off)
 {
     const rb_iseq_t *iseq = rb_method_for_self_aref(name, off, &struct_aref_builtin);
+    iseq->body->builtin_inline_p = true;
 
     rb_add_method_iseq(nstr, SYM2ID(name), iseq, NULL, METHOD_VISI_PUBLIC);
 }
-- 
cgit v0.10.2


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

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