1. Computing

YARV - Yet Another Ruby VM

By

Probably the most exciting and visible change in Ruby 1.9 is the addition of a bytecode interpreter for Ruby. The YARV (Yet Another Ruby VM) interpreter was integrated into the Ruby project, replacing the interpreter created by Matz (aka MRI, Matz's Ruby Interpreter). All your code will run just the same, but a lot has changed under the hood.

When a program is parsed, a syntax tree is created. This is a hierarchical tree of all tokens (identifiers, keywords, operators, etc) in the program. The MRI would iterate over this tree directly when running Ruby programs. While this may be simpler to implement, it takes more memory and is quite inefficient in the long run.

YARV takes a vastly different approach to the problem of running Ruby programs. After the program is parsed and the syntax tree created, program for a virtual machine is created. At this point, the structure of the original program is lost, and instead the statements represented as a more efficient program. YARV then executes this program on a virtual machine (similar to an emulator), without having to traverse the syntax tree more than once.

What this means for you is faster execution times. Ruby was once considered one of the slowest computer languages in wide use. It was just slow and inefficient, sometimes prohibitively slow. Now, with YARV, performance is increased dramatically, putting Ruby closer to Python (which is considered fast for a modern scripting language) in terms of performance.

  1. About.com
  2. Computing
  3. Ruby
  4. Beginning Ruby
  5. New in Ruby 1.9.x
  6. YARV - Yet Another Ruby VM

©2014 About.com. All rights reserved.