———– JIT ————-
The crystalizer is a loose wrapper for a ruby2c converter called ruby2cext. It takes your ruby code, creates its rubyC equivalent, and re-loadsthe C version over the top of it, thus effectively JIT-ing your existing Ruby code. It is called crystalizer because it effectively should be called after setting up existing classes and methods, so that when it can “crystalize” the calls to existing methods, by cacheing their location. Thus, it is not 100% ruby compatible, and currently loses some backtrace information. It has proven quite a bit faster than 1.9 in some benchmarks, though it is currently only 1.8 compatible [presumably if it were 1.9 compatible, it might be even faster].
klass.concretize! # concretizes all interior methods of this class
of, if you have several classes and don't want to have to remember exactly which ones to concretize:
# do some stuff here # after completing this block, it will concretize any and all classes it ran into in the course of the block # so the second and third times through this block should be faster [or any other code that subsequently calls those classes]
And for the daring:
Ruby2CExtension::Conretize.concretize_all! # optimizes all known classes in the current Ruby VM – takes forever, might discover bugs in edge cases that aren't covered.
Also an option is the rb2cx executable $ rb2cx ruby_filename.rb
creates ruby_filename.so based on ruby_filename.rb. Thus you could run the ruby script's c equivalent thus: $ ruby -rruby_filename.so -e ''
Much thanks to the original author of Ruby2CExtension, since this is only a wrapper to his work.
Note that crystalize won't crystalize existing procs in the system–they stay as pure Ruby–it crystalizes methods and future procs created from/within those methods, however.
Ruby2CExtension is a Ruby to C extension translator/compiler. It takes any Ruby source file, parses it using Ruby's builtin parser and then translates the abstract syntax tree into “equivalent” C extension code.
Ruby 1.8.4, 1.8.5 or 1.8.6 (possibly 1.8.7–haven't tried)
RubyNode (available at rubynode.rubyforge.org/)
Just run (as root): TODO
gem install ruby2cext
Or if you do not use the gem:
This will install Ruby2CExtension to the default locations. Optionally you can supply some options to setup.rb to customize the installation (see “ruby setup.rb –help”).
Please see doc/index.html for more documentation.
Copyright 2006-2007 Dominik Bathon <[email protected]>
Ruby2CExtension is licensed under the same terms as Ruby.