Nick Sieger: RubyConf: YARV on Rails http://blog.nicksieger.com/articles/2006/10/23/rubyconf-yarv-on-rails en-us 40 RubyConf: YARV on Rails <h2>Koichi SASADA</h2> <p><em>Update: corrected performance numbers &#45;&#45; 20x, not 20%!</em></p> <ul> <li>Got a job developing YARV at the University of Tokyo! He&#8217;s now employed at Akhihabara, Otaku City&#46;</li> <li>Member of Nihon&#45;Ruby&#45;no&#45;Kai</li> <li>Present at RubyKaigi 2006 (200 tickets sold in 3 hours)&#46; RubyKaigi 2007 will be June 9&#45;10 (Saturday and Sunday)&#46;</li> <li>Member of Nihon&#45;Perl&#45;no&#45;Kai</li> <li>Co&#45;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&#46;rb, add a <code>GC.disable</code> line (there&#8217;s a bug to be fixed when he gets back to Japan)&#46;</li> <li>Start up WEBrick, and it works!</li> </ul> <h2>Glossary</h2> <ul> <li>Rite: code name of Ruby 2&#46;0 (a&#46;k&#46;a&#46; 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&#45;time optimization, native threading, specialized instructions, instruction unification, inline method cache, and stack caching&#46; YARV can build with configure/make, but doesn&#8217;t work with AC 2&#46;6 (maybe you know why?)&#46; It passes most of the Ruby tests, but misses a few due to implementation differences&#46;</p> <p>[Koichi showed a demo controlling iTunes on Windows with Win32/OLE with YARV, and a native&#45;threaded scenario in IRB&#46;]</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&#46; It provides up to a 20x speed up for some algorithm benchmarks (Ackermann, Fib), but not for others [graphs shown]&#46; You assemble and disassemble YARV instruction sequences, or serialize and de&#45;serialize them&#46; They are just Ruby literals, so they can be packed in YAML or some other human&#45;readable format&#46;</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"># =&gt; (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)&#46; Only the thread that has the lock can run&#46; No need for sync, but no parallelism</li> <li>Thread model 3: Ruby threads in parallel, but when thread&#45;unsafe code is executing, GL needs to be obtained</li> <li>Mutex class will become builtin</li> <li>Thread&#46;critical will vanish (not obsolete, but unsupported) [this was a controversial point for some &#45;&#45; the comment was that it&#8217;s a near impossibility to keep it with a native threading model though, the two are in compatible]</li> </ul> <p>Matz: 1&#46;9&#46;1 in 2007 Christmas, but Ruby 1&#46;9&#46;1 is also to be merged with YARV, so Koichi hopes to complete the merge by spring or summer 2007&#46; Thread model 2 will need to be used to begin with&#46;</p> <h2>Future</h2> <ul> <li><code>set_trace_func</code> hook functions &#45;&#45; 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&#46;]</li> <li>Catch up with Ruby 1&#46;9</li> <li>JIT/AOT compiler (AOT compiler started but incomplete)</li> <li>Koichi also has a side project: high&#45;performance Ruby, with the goal of making it easy to write performant code&#46;</li> </ul> <h2>Links</h2> <ul> <li><a href="http://www.atdot.net/yarv/">http://www&#46;atdot&#46;net/yarv/</a></li> <li>ML: yarv&#45;dev and yarv&#45;dev&#45;en &#45;&#45; Bug tracking with &#8220;Subject: [BUG] foo bar&#8221;</li> <li><a href="http://www.atdot.net/~ko1/yarvbugs">http://www&#46;atdot&#46;net/~ko1/yarvbugs</a></li> <li><a href="http://i.loveruby.net/autobuild/yarv">http://i&#46;loveruby&#46;net/autobuild/yarv</a> &#45;&#45; YARV build process</li> </ul> <p>More developers and testers are welcomed to the project!</p> Mon, 23 Oct 2006 14:15:00 +0000 urn:uuid:b15da1fc-f69e-4ff2-899b-0a141f61ab21 Nick Sieger http://blog.nicksieger.com/articles/2006/10/23/rubyconf-yarv-on-rails ruby rubyconf rubyconf2006 http://blog.nicksieger.com/articles/trackback/96