Nick Sieger: RubyConf: YARV on Railstag:blog.nicksieger.com,2005:TypoTypo2007-08-31T16:57:20+00:00Nick Siegerurn:uuid:b15da1fc-f69e-4ff2-899b-0a141f61ab212006-10-23T14:15:00+00:002007-08-31T16:57:20+00:00RubyConf: YARV on Rails<h2>Koichi SASADA</h2>
<p><em>Update: corrected performance numbers – 20x, not 20%!</em></p>
<ul>
<li>Got a job developing YARV at the University of Tokyo! He’s now employed at Akhihabara, Otaku City.</li>
<li>Member of Nihon-Ruby-no-Kai</li>
<li>Present at RubyKaigi 2006 (200 tickets sold in 3 hours). RubyKaigi 2007 will be June 9-10 (Saturday and Sunday).</li>
<li>Member of Nihon-Perl-no-Kai</li>
<li>Co-author of Perl book on Parrot in Japanese</li>
</ul>
<h2>DEMO</h2>
<ul>
<li>[Demo creating Rails app]</li>
<li>Create app with YARV (<code>rails foobar</code>)</li>
<li>Edit config/boot.rb, add a <code>GC.disable</code> line (there’s a bug to be fixed when he gets back to Japan).</li>
<li>Start up WEBrick, and it works!</li>
</ul>
<h2>Glossary</h2>
<ul>
<li>Rite: code name of Ruby 2.0 (a.k.a. vaporware!)</li>
<li>YARV: Yet Another Ruby VM</li>
</ul>
<h2>YARV</h2>
<ul>
<li>Supported by funds from IPA (now finished)</li>
<li>Simple stack machine, with VM instructions, a compiler and interpreter</li>
<li>Optimization techniques to improve performance</li>
<li>Open source</li>
</ul>
<p>Optimizations include compile-time optimization, native threading, specialized instructions, instruction unification, inline method cache, and stack caching. YARV can build with configure/make, but doesn’t work with AC 2.6 (maybe you know why?). It passes most of the Ruby tests, but misses a few due to implementation differences.</p>
<p>[Koichi showed a demo controlling iTunes on Windows with Win32/OLE with YARV, and a native-threaded scenario in IRB.]</p>
<p><strong>Myths of YARV</strong>: YARV is great! YARV will solve all problems! It makes Ruby programs go 50 times faster! It solves character issues! It finds your girlfriend!</p>
<p><strong>Truths</strong>: YARV is for running Ruby programs, fast. It provides up to a 20x speed up for some algorithm benchmarks (Ackermann, Fib), but not for others [graphs shown]. You assemble and disassemble YARV instruction sequences, or serialize and de-serialize them. They are just Ruby literals, so they can be packed in YAML or some other human-readable format.</p>
<div class="typocode"><pre><code class="typocode_ruby "><span class="ident">require</span> <span class="punct">'</span><span class="string">yasm</span><span class="punct">'</span>
<span class="ident">require</span> <span class="punct">'</span><span class="string">yaml</span><span class="punct">'</span>
<span class="ident">iseq</span> <span class="punct">=</span> <span class="constant">YASM</span><span class="punct">.</span><span class="ident">toplevel</span><span class="punct">([</span><span class="symbol">:a</span><span class="punct">,</span> <span class="symbol">:b</span><span class="punct">])</span> <span class="punct">{|</span><span class="ident">ib</span><span class="punct">|</span>
<span class="ident">ib</span><span class="punct">.</span><span class="ident">answer</span>
<span class="ident">ib</span><span class="punct">.</span><span class="ident">leave</span>
<span class="punct">}</span>
<span class="ident">p</span> <span class="ident">iseq</span><span class="punct">.</span><span class="ident">to_a</span><span class="punct">.</span><span class="ident">to_yaml</span> <span class="comment"># => (gave a readable YAML view of the assembly)</span></code></pre></div>
<h2>Threading</h2>
<ul>
<li>Ruby thread is mapped 1:1 to a native thread</li>
<li>Supports POSIX and Win32</li>
<li>Many existing Ruby libraries are not synchronized at the C level, so many C libraries need synchronization added to them</li>
<li>Thread model 2: 1:1 mapping, with a Giant Lock (GL). Only the thread that has the lock can run. No need for sync, but no parallelism</li>
<li>Thread model 3: Ruby threads in parallel, but when thread-unsafe code is executing, GL needs to be obtained</li>
<li>Mutex class will become builtin</li>
<li>Thread.critical will vanish (not obsolete, but unsupported) [this was a controversial point for some – the comment was that it’s a near impossibility to keep it with a native threading model though, the two are in compatible]</li>
</ul>
<p>Matz: 1.9.1 in 2007 Christmas, but Ruby 1.9.1 is also to be merged with YARV, so Koichi hopes to complete the merge by spring or summer 2007. Thread model 2 will need to be used to begin with.</p>
<h2>Future</h2>
<ul>
<li><code>set_trace_func</code> hook functions – what to do here? [It was suggested by Charles Nutter to remove it, to which Matz replied that we could as long as we have a good replacement debugging API.]</li>
<li>Catch up with Ruby 1.9</li>
<li>JIT/AOT compiler (AOT compiler started but incomplete)</li>
<li>Koichi also has a side project: high-performance Ruby, with the goal of making it easy to write performant code.</li>
</ul>
<h2>Links</h2>
<ul>
<li><a href="http://www.atdot.net/yarv/">http://www.atdot.net/yarv/</a></li>
<li>ML: yarv-dev and yarv-dev-en – Bug tracking with “Subject: [BUG] foo bar”</li>
<li><a href="http://www.atdot.net/~ko1/yarvbugs">http://www.atdot.net/~ko1/yarvbugs</a></li>
<li><a href="http://i.loveruby.net/autobuild/yarv">http://i.loveruby.net/autobuild/yarv</a> – YARV build process</li>
</ul>
<p>More developers and testers are welcomed to the project!</p>