https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112013-12-08T11:10:11ZRuby Issue Tracking SystemRuby master - Bug #9227: use opt_aset ?https://bugs.ruby-lang.org/issues/9227?journal_id=435062013-12-08T11:10:11Ztmm1 (Aman Karmani)ruby@tmm1.net
<ul></ul><p>Maybe some minor improvement on microbenchmarks.</p>
<p>Before patch:</p>
<p>./miniruby -I. benchmark/bm_so_k_nucleotide.rb > /dev/null 1.54s user 0.02s system 99% cpu 1.572 total<br>
./miniruby -I. benchmark/bm_so_k_nucleotide.rb > /dev/null 1.58s user 0.02s system 99% cpu 1.608 total<br>
./miniruby -I. benchmark/bm_so_k_nucleotide.rb > /dev/null 1.54s user 0.02s system 99% cpu 1.565 total<br>
./miniruby -I. benchmark/bm_so_k_nucleotide.rb > /dev/null 1.57s user 0.02s system 99% cpu 1.605 total<br>
./miniruby -I. benchmark/bm_so_k_nucleotide.rb > /dev/null 1.54s user 0.02s system 99% cpu 1.569 total</p>
<p>After patch:</p>
<p>./miniruby -I. benchmark/bm_so_k_nucleotide.rb > /dev/null 1.51s user 0.02s system 99% cpu 1.535 total<br>
./miniruby -I. benchmark/bm_so_k_nucleotide.rb > /dev/null 1.52s user 0.02s system 99% cpu 1.545 total<br>
./miniruby -I. benchmark/bm_so_k_nucleotide.rb > /dev/null 1.49s user 0.02s system 99% cpu 1.515 total<br>
./miniruby -I. benchmark/bm_so_k_nucleotide.rb > /dev/null 1.54s user 0.02s system 99% cpu 1.567 total<br>
./miniruby -I. benchmark/bm_so_k_nucleotide.rb > /dev/null 1.50s user 0.02s system 99% cpu 1.530 total</p> Ruby master - Bug #9227: use opt_aset ?https://bugs.ruby-lang.org/issues/9227?journal_id=435472013-12-09T19:30:12Zko1 (Koichi Sasada)
<ul><li><strong>Assignee</strong> set to <i>ko1 (Koichi Sasada)</i></li></ul><p>I forget why I remove it.<br>
Maybe I can't measure improvement (and possible to have trouble with this insn).</p>
<p>If there are no regression, I don't against to use it.</p> Ruby master - Bug #9227: use opt_aset ?https://bugs.ruby-lang.org/issues/9227?journal_id=435962013-12-11T12:57:59Ztmm1 (Aman Karmani)ruby@tmm1.net
<ul></ul><p>I did some more microbenchmarks. In the Array#[Fixnum]= case, the new instruction makes a huge difference.</p>
<p>Before:<br>
array aset 1.430000 0.000000 1.430000 ( 1.430370)<br>
array aset 1.430000 0.000000 1.430000 ( 1.429422)<br>
array aset 1.520000 0.000000 1.520000 ( 1.544912)<br>
array aset 1.440000 0.000000 1.440000 ( 1.444454)</p>
<p>After:<br>
array aset 0.910000 0.000000 0.910000 ( 0.908866)<br>
array aset 0.910000 0.000000 0.910000 ( 0.910356)<br>
array aset 0.890000 0.000000 0.890000 ( 0.891267)<br>
array aset 0.920000 0.000000 0.920000 ( 0.921012)</p>
<p>Benchmark:</p>
<p>require 'benchmark'<br>
Benchmark.bmbm(20) do |b|<br>
ary = [1,2,3,4]<br>
b.report('array aset') do<br>
10_000_000.times do<br>
ary[2] = 2<br>
ary[3] = 3<br>
end<br>
end<br>
end</p>
<p>Here's a copy of the patch that applies on trunk:</p>
<p>diff --git a/compile.c b/compile.c<br>
index af11baf..25e3652 100644<br>
--- a/compile.c<br>
+++ b/compile.c<br>
@@ -1955,6 +1955,11 @@ iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj)<br>
case idAREF: SP_INSN(aref); return COMPILE_OK;<br>
}<br>
break;</p>
<ul>
<li>
<pre><code> case 2:
</code></pre>
</li>
<li>
<pre><code> switch (ci->mid) {
</code></pre>
</li>
<li>
<pre><code> case idASET: SP_INSN(aset); return COMPILE_OK;
</code></pre>
</li>
<li>
<pre><code> }
</code></pre>
</li>
<li>
<pre><code> break;
}
</code></pre>
}<br>
if (ci->flag & VM_CALL_ARGS_SKIP_SETUP) {</li>
</ul> Ruby master - Bug #9227: use opt_aset ?https://bugs.ruby-lang.org/issues/9227?journal_id=435972013-12-11T13:00:36Zko1 (Koichi Sasada)
<ul></ul><p>OK. Please enable it.</p> Ruby master - Bug #9227: use opt_aset ?https://bugs.ruby-lang.org/issues/9227?journal_id=436012013-12-11T15:38:46Ztmm1 (Aman Karmani)ruby@tmm1.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r44136.<br>
Aman, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<p>compile.c: add opt_aset instruction for faster Hash#[]= and Array#[]=</p>
<ul>
<li>compile.c (iseq_specialized_instruction): emit opt_aset instruction<br>
to optimize Hash#[]= and Array#[]= when called with Fixnum argument.<br>
[Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: use opt_aset ? (Closed)" href="https://bugs.ruby-lang.org/issues/9227">#9227</a>] <a href="/issues/9227">[ruby-core:58956]</a></li>
</ul>