Compiling a Ruby app

Ken B. wrote:

Thats the problem of decompiling native code to a language. Usually,
Bytecodes like Java and .NET are very well decompilable, because they
retain a lot of the language instructions within the code.

[snip]
because in Java,
the JVM does the optimization, not the compiler.

It’s worth mentioning that these are not mutually exclusive.

For example, the LLVM seems to be capable of doing all of the above, to
some extent. They describe it as compile-time, link-time, run-time, and
idle-time optimizations.

I really see no reason you couldn’t have a language like Ruby in which
the obvious stuff is pre-optimized beyond recognition, and the more
dynamic stuff is optimized at runtime. In fact, I suspect we’d get most
of this for free, if Rubinius ever finishes that LLVM port I keep
hearing about.

I think my old example still holds:

class Foo
%w(one two three four five).each_with_index do |name, index|
define_method(name) { index }
end
end

A particularly aggressive/intelligent compiler might be able to even
inline that into:

class Foo
def one
1
end
def two

end

Each additional compile-time optimization gets harder (both conceptually
and in computation time), because of the nature of Ruby, but also
obfuscates the result that much more.

David M. wrote:

hearing about.
LLVM does no dynamic optimization at runtime; it only does static
optimizations.

The most interesting LLVM project to me is one that uses LLVM as a
backend for the Hotspot JVM (OpenJDK), allowing Hotspot’s dynamic
optimizations to couple with LLVM’s static ones.

http://icedtea.classpath.org/wiki/ZeroSharkFaq

  • Charlie