Compiling a Ruby app

Ken Bloom wrote:

I was speaking of compiled languages in general. As a trivial example,
a common C optimization is to inline functions which are below a
certain size. Now, when decompiling, how do I know what was inlined,
and what really should be duplicate code?
      

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.

···

On Wed, 04 Mar 2009 11:52:29 -0500, Florian Gilcher wrote:

On Mar 4, 2009, at 12:47 PM, David Masover wrote:

David Masover wrote:

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.

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