I am happy to announce the release of Ruby2CExtension 0.2.0.
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.
More information at http://ruby2cext.rubyforge.org/.
Ruby2CExtension is available as gem now, so installation is as simple
as:
gem install ruby2cext
(There is also a setup.rb-release available.)
Ruby2CExtension 0.2.0 supports Ruby 1.8.4 to 1.8.6 (including the
patchlevel releases).
The two major new features are Eval2C and the new optimizations.
Eval2C allows transparent compilation of Ruby code at runtime. This
allows to compile (and speedup) code that is generated at runtime. It
also makes it possible to compile only selected parts of Ruby files.
This
feature is similar to RubyInline, but works with Ruby code instead of C
code.
More information at http://ruby2cext.rubyforge.org/eval2c.html.
The new optional optimizations can provide speedups for Ruby code by
sacrificing some compatibility. In particular the optimization of calls
to (C-implemented) methods of built-in classes can significantly speedup
Ruby code.
Example:
max = 2000
z = x = 0
while (x+=1) <= max
y = 0
while (y+=1) <= max
z = (x+y-z) % 32000
end
end
puts z
The compiled version (with all optimizations turned on) of this program
is about seven times faster than the uncompiled version. This is an
extreme example, because almost all method calls are optimized, but it
shows what is possible.
More information at http://ruby2cext.rubyforge.org/optimizations.html.
Changelog:
-
New features:
- New plugin architecture for optimizations and other things
- Optimization plugins: const_cache, builtin_methods, inline_methods,
case_optimize - Other plugins: require_include, warnings
- Eval2C for compilation at runtime
- Available as gem now
-
Improvements:
- Implemented control flow “through” rescue/ensure clauses
- Better vmode handling
- Support for Ruby 1.8.5 and 1.8.6
- Improved performance for global variables
-
Fixes:
- Workaround for an issue with ALLOCA_N in while loops
- Fixed a problem with case/when (missing newline nodes)
- Removed libraries from compile command
- Various other small fixes