# Ruby Compiler

**URL:** <https://www.ruby-forum.com/t/ruby-compiler/132597>\
**Category:** Ruby\
**Created:** [March 21, 2008, 6:49pm UTC](https://www.ruby-forum.com/t/ruby-compiler/132597 "2008-03-21T18:49:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![phasis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e56c9b/32.png) [@phasis](https://www.ruby-forum.com/u/phasis)\
**Post date:** [March 21, 2008, 6:49pm UTC](https://www.ruby-forum.com/t/ruby-compiler/132597/1 "2008-03-21T18:49:47Z")

</div>

Hi,

I longed for a ruby byte code compiler.  
But I guess YARV is not stable until now.

So I made a very experimental Ruby Compiler.  
Actually it is not a true compiler just ruby object dumper and loader.  
By modifing gc.c and eval.c , It cannot be distibuted as extension  
library.

The main idea is simple.

1. Dump all symbols,ids and node tree to a file.
2. Load the symbols,ids and tree from a file and run.

But I should have spent much time to understand how to parsing and  
evalualing  
the ruby code.

With this compiler, you can secure your source code.  
And saving parsing time is the main advantage.  
Even the same object file can runs on Linux and Windows just like Java  
class.

What do you think about this compiler?

Regards,

Park H.

---

<div class="post-metadata">

**Author:** ![phasis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e56c9b/32.png) [@phasis](https://www.ruby-forum.com/u/phasis)\
**Post date:** [March 21, 2008, 11:16pm UTC](https://www.ruby-forum.com/t/ruby-compiler/132597/2 "2008-03-21T23:16:54Z")

</div>

On 21 mar, 14:49, Heesob P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The main idea is simple.  
> class.
> 
> What do you think about this compiler?

Looks interesting , one question:

Does the loading for the parsed/node tree generated dump avoid  
evaluation? I mean, there is no need to reparse it, right? If so, then  
you have a speed boost when loading pre-compiled ruby scripts and  
sounds good.

How it handles reload of files (using load ‘foo.rb’ compares the mtime  
of the pre-compiled file with the source file?)

Regards,

---

<div class="post-metadata">

**Author:** ![phasis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e56c9b/32.png) [@phasis](https://www.ruby-forum.com/u/phasis)\
**Post date:** [March 21, 2008, 11:39pm UTC](https://www.ruby-forum.com/t/ruby-compiler/132597/3 "2008-03-21T23:39:46Z")

</div>

On 22 Mrz., 05:11, Luis L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Actually it is not a true compiler just ruby object dumper and loader.
> 
> evaluation? I mean, there is no need to reparse it, right? If so, then  
> you have a speed boost when loading pre-compiled ruby scripts and  
> sounds good.
> 
> How it handles reload of files (using load ‘foo.rb’ compares the mtime  
> of the pre-compiled file with the source file?)

This concept can only work on special written files that are not doing  
any  
evaluation during load. Unfortunately almost none of the files in the  
standard library do fit into this schema.

---

<div class="post-metadata">

**Author:** ![phasis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e56c9b/32.png) [@phasis](https://www.ruby-forum.com/u/phasis)\
**Post date:** [March 22, 2008, 2:10am UTC](https://www.ruby-forum.com/t/ruby-compiler/132597/4 "2008-03-22T02:10:48Z")

</div>

Hi,  
----- Original Message -----  
From: “llothar” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Newsgroups: comp.lang.ruby  
To: “ruby-talk ML” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Saturday, March 22, 2008 7:35 AM  
Subject: Re: Ruby Compiler

> > > So I made a very experimental Ruby Compiler.  
> > > the ruby code.  
> > > Does the loading for the parsed/node tree generated dump avoid  
> > > evaluation during load. Unfortunately almost none of the files in the  
> > > standard library do fit into this schema.

I don’t think so. My compiler is just dump and load the first parsed  
node tree snapshot.  
So you can use it for all case regardless of evaluation during load.  
It is same to the ruby interpreter except for the source is parsed or  
not.

Regards,  
Park H.

---

<div class="post-metadata">

**Author:** ![phasis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e56c9b/32.png) [@phasis](https://www.ruby-forum.com/u/phasis)\
**Post date:** [March 22, 2008, 2:43am UTC](https://www.ruby-forum.com/t/ruby-compiler/132597/5 "2008-03-22T02:43:10Z")

</div>

Hi,

In message “Re: Ruby Compiler”  
on Sat, 22 Mar 2008 09:56:28 +0900, “Park H.”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|\> Does the loading for the parsed/node tree generated dump avoid  
|\> evaluation? I mean, there is no need to reparse it, right? If so, then  
|\> you have a speed boost when loading pre-compiled ruby scripts and  
|\> sounds good.  
|\>  
|Yes, of course. The main purpose is speed up.

Have you measured the performance of the “compiler”?

```
          matz.

```

---

<div class="post-metadata">

**Author:** ![phasis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e56c9b/32.png) [@phasis](https://www.ruby-forum.com/u/phasis)\
**Post date:** [March 22, 2008, 2:00am UTC](https://www.ruby-forum.com/t/ruby-compiler/132597/6 "2008-03-22T02:00:16Z")

</div>

Hi,  
----- Original Message -----  
From: “Luis L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Newsgroups: comp.lang.ruby  
To: “ruby-talk ML” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Saturday, March 22, 2008 7:15 AM  
Subject: Re: Ruby Compiler

> > Even the same object file can runs on Linux and Windows just like Java  
> > sounds good.

Yes, of course. The main purpose is speed up.

> How it handles reload of files (using load ‘foo.rb’ compares the mtime  
> of the pre-compiled file with the source file?)

More work is needed for this problem. Currently it direcly loads the  
pre-compiled file.

> ## Regards,
> 
> Luis L.

Regards,  
Park H.

---

<div class="post-metadata">

**Author:** ![phasis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e56c9b/32.png) [@phasis](https://www.ruby-forum.com/u/phasis)\
**Post date:** [March 22, 2008, 3:55am UTC](https://www.ruby-forum.com/t/ruby-compiler/132597/7 "2008-03-22T03:55:29Z")

</div>

Hi,  
----- Original Message -----  
From: “Yukihiro M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: “ruby-talk ML” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Saturday, March 22, 2008 10:42 AM  
Subject: Re: Ruby Compiler

> |Yes, of course. The main purpose is speed up.
> 
> Have you measured the performance of the “compiler”?

Actually the performance is not as good as I expected.  
For the simple source code, the peformance is not better than ruby  
interpreter.  
If the parsing time takes longer, the performance is better enough.  
I guess the web environment ruby code like Ruby On Rails can have some  
performance gain.

> matz.

Regards,  
Park H.

---

<div class="post-metadata">

**Author:** ![phasis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e56c9b/32.png) [@phasis](https://www.ruby-forum.com/u/phasis)\
**Post date:** [March 22, 2008, 12:47pm UTC](https://www.ruby-forum.com/t/ruby-compiler/132597/8 "2008-03-22T12:47:19Z")

</div>

Hi,  
----- Original Message -----  
From: “Yukihiro M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: “ruby-talk ML” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Saturday, March 22, 2008 4:51 PM  
Subject: Re: Ruby Compiler

> |I guess the web environment ruby code like Ruby On Rails can have some performance gain.
> 
> Last time I have benchmarked, parsing time was not significant. I am  
> very interested in how much this approach works for what kind of  
> situation, say RoR.

I realized the parsing time is not an issue of performance after several  
tests.  
So the performance gain with skipping parsing might be just a vain  
efforts.  
For the real speed up, I believe the optimization of node tree is  
required.  
Thank you for your attention.

Regards,  
Park H.

---

<div class="post-metadata">

**Author:** ![phasis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e56c9b/32.png) [@phasis](https://www.ruby-forum.com/u/phasis)\
**Post date:** [March 22, 2008, 8:52am UTC](https://www.ruby-forum.com/t/ruby-compiler/132597/9 "2008-03-22T08:52:53Z")

</div>

Hi,

In message “Re: Ruby Compiler”  
on Sat, 22 Mar 2008 11:54:40 +0900, “Park H.”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|\> Have you measured the performance of the “compiler”?  
|  
|Actually the performance is not as good as I expected.  
|For the simple source code, the peformance is not better than ruby interpreter.  
|If the parsing time takes longer, the performance is better enough.  
|I guess the web environment ruby code like Ruby On Rails can have some performance gain.

Last time I have benchmarked, parsing time was not significant. I am  
very interested in how much this approach works for what kind of  
situation, say RoR.

```
          matz.

```
