# Compiled Ruby executables

**URL:** <https://rubytalk.org/t/compiled-ruby-executables/3887>\
**Category:** ruby-talk\
**Created:** [2 January 2003 00:57 UTC](https://rubytalk.org/t/compiled-ruby-executables/3887 "2003-01-02T00:57:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philip\_Mak1](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Philip\_Mak1](https://rubytalk.org/u/Philip_Mak1)\
**Post date:** [2 January 2003 00:57 UTC](https://rubytalk.org/t/compiled-ruby-executables/3887/1 "2003-01-02T00:57:54Z")

</div>

Is it possible to substantially increase Ruby’s execution speed by  
compiling it to an EXE file?

I think I heard about a project somewhere that’s like Jython, which  
can compile Ruby to Java bytecode. If that exists, then, one could  
compile the Java bytecode to an optimized native executable using GCJ  
or another commercial Java bytecode to EXE tool.

Does this exist? If so, how well/fast does it work?

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [2 January 2003 03:00 UTC](https://rubytalk.org/t/compiled-ruby-executables/3887/2 "2003-01-02T03:00:44Z")

</div>

Hi,

> Is it possible to substantially increase Ruby’s execution speed by  
> compiling it to an EXE file?

There were rb2c (ruby to C translator) and rbjit (ruby JIT),  
but they’ve not been maintained so long.

> I think I heard about a project somewhere that’s like Jython, which  
> can compile Ruby to Java bytecode. If that exists, then, one could  
> compile the Java bytecode to an optimized native executable using GCJ  
> or another commercial Java bytecode to EXE tool.

AFAIK, Jython is an implementation of Python by Java, and  
doesn’t compile the source to bytecode. Also JRuby is similar.

> **···**
>
> At Thu, 2 Jan 2003 09:57:54 +0900, Philip Mak wrote:
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Daniel\_Carrera](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Daniel\_Carrera](https://rubytalk.org/u/Daniel_Carrera)\
**Post date:** [2 January 2003 04:43 UTC](https://rubytalk.org/t/compiled-ruby-executables/3887/3 "2003-01-02T04:43:53Z")

</div>

> Is it possible to substantially increase Ruby’s execution speed by  
> compiling it to an EXE file?

Execution speed will not be increased very much by this method.  
The binary executable will still contain a copy of the ruby interpreter  
which will run the ruby code much the same way as the original.

> I think I heard about a project somewhere that’s like Jython, which can  
> compile Ruby to Java bytecode. If that exists, then, one could compile  
> the Java bytecode to an optimized native executable using GCJ or another  
> commercial Java bytecode to EXE tool.

It’s called JRuby. It’s not a Ruby-to-Java compiler, but a ruby  
interpreter written in Java.

Even if you compiled to Java:

1. Java is not very fast anyways.
2. Compiling Java to an executable has the same problems I described above.

Do not despair, for there is yet one alternative:

Most programs follow the 80/20 rule. That is, 80% of the time is spent in  
20% of the code. If this is your situation, you can optimize the  
time-critical portion of your code by writing it in C, and making it a  
ruby extension. This portion of the code will run at the original C  
speed. Depending on the problem at hand, you might see dramatic  
improvements in execution.

I’ve glanced at the Ruby API, and it looks very easy to use. I suggest  
you consider this option.

Cheers,  
Daniel.

---

<div class="post-metadata">

**Author:** ![Anders\_Bengtsson](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@Anders\_Bengtsson](https://rubytalk.org/u/Anders_Bengtsson)\
**Post date:** [2 January 2003 19:25 UTC](https://rubytalk.org/t/compiled-ruby-executables/3887/4 "2003-01-02T19:25:00Z")

</div>

Jython actually has a bytecode compiler available.

We plan to create one for JRuby too, in our copious free time. 🙂

/Anders

> **···**
>
> [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> 
> > AFAIK, Jython is an implementation of Python by Java, and  
> > doesn’t compile the source to bytecode. Also JRuby is similar.
> 
> –
> 
> A n d e r s B e n g t s s o n | ndrsbngtssn@yahoo.se  
> Stockholm, Sweden |
> 
> * * *
> 
> Gratis e-mail resten av livet på www.yahoo.se/mail  
> Busenkelt!

---

<div class="post-metadata">

**Author:** ![Shashank\_Date3](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Shashank\_Date3](https://rubytalk.org/u/Shashank_Date3)\
**Post date:** [3 January 2003 05:32 UTC](https://rubytalk.org/t/compiled-ruby-executables/3887/5 "2003-01-03T05:32:35Z")

</div>

“Anders Bengtsson” [ndrsbngtssn@yahoo.se](mailto:ndrsbngtssn@yahoo.se) wrote in message

> We plan to create one for JRuby too, in our copious free time. 🙂

Mean while, Matz is working on his little secret compiler ([57771],[58028])  
(Guess which: Squeak ? Scheme-48? Parrot? gforth? ;-))

Just wait and see …  
– shanko
