# Ruby Compiler

**URL:** <https://rubytalk.org/t/ruby-compiler/45329>\
**Category:** ruby-talk\
**Created:** [21 March 2008 17:49 UTC](https://rubytalk.org/t/ruby-compiler/45329 "2008-03-21T17:49:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Heesob\_Park](https://avatars.discourse-cdn.com/v4/letter/h/3bc359/32.png) [@Heesob\_Park](https://rubytalk.org/u/Heesob_Park)\
**Post date:** [21 March 2008 17:49 UTC](https://rubytalk.org/t/ruby-compiler/45329/1 "2008-03-21T17:49:37Z")

</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 Heesob

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Luis\_Lavena1](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@Luis\_Lavena1](https://rubytalk.org/u/Luis_Lavena1)\
**Post date:** [21 March 2008 22:15 UTC](https://rubytalk.org/t/ruby-compiler/45329/2 "2008-03-21T22:15:05Z")

</div>

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,

> **···**
>
> On 21 mar, 14:49, Heesob Park \<pha...@gmail.com\> wrote:
> 
> > 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?
> 
> --  
> Luis Lavena

---

<div class="post-metadata">

**Author:** ![Lothar\_Scholz1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lothar\_Scholz1](https://rubytalk.org/u/Lothar_Scholz1)\
**Post date:** [21 March 2008 22:35 UTC](https://rubytalk.org/t/ruby-compiler/45329/3 "2008-03-21T22:35:02Z")

</div>

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.

> **···**
>
> On 22 Mrz., 05:11, Luis Lavena \<luislav...@gmail.com\> wrote:
> 
> > On 21 mar, 14:49, Heesob Park \<pha...@gmail.com\> wrote:
> > 
> > \> 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?
> > 
> > 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?)

---

<div class="post-metadata">

**Author:** ![Park\_Heesob1](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Park\_Heesob1](https://rubytalk.org/u/Park_Heesob1)\
**Post date:** [22 March 2008 00:56 UTC](https://rubytalk.org/t/ruby-compiler/45329/4 "2008-03-22T00:56:28Z")

</div>

Hi,

> **···**
>
> ----- Original Message -----  
> From: "Luis Lavena" \<luislavena@gmail.com\>  
> Newsgroups: comp.lang.ruby  
> To: "ruby-talk ML" \<ruby-talk@ruby-lang.org\>  
> Sent: Saturday, March 22, 2008 7:15 AM  
> Subject: Re: Ruby Compiler
> 
> > On 21 mar, 14:49, Heesob Park \<pha...@gmail.com\> wrote:
> > 
> > > 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?
> > 
> > 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.
> 
> 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 Lavena
> 
> Regards,  
> Park Heesob

---

<div class="post-metadata">

**Author:** ![Park\_Heesob1](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Park\_Heesob1](https://rubytalk.org/u/Park_Heesob1)\
**Post date:** [22 March 2008 01:09 UTC](https://rubytalk.org/t/ruby-compiler/45329/5 "2008-03-22T01:09:12Z")

</div>

Hi,

> **···**
>
> ----- Original Message -----  
> From: "llothar" \<llothar@web.de\>  
> Newsgroups: comp.lang.ruby  
> To: "ruby-talk ML" \<ruby-talk@ruby-lang.org\>  
> Sent: Saturday, March 22, 2008 7:35 AM  
> Subject: Re: Ruby Compiler
> 
> > On 22 Mrz., 05:11, Luis Lavena \<luislav...@gmail.com\> wrote:
> > 
> > > On 21 mar, 14:49, Heesob Park \<pha...@gmail.com\> wrote:
> > > 
> > > \> 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?
> > > 
> > > 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?)
> > 
> > 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.
> 
> 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 Heesob

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [22 March 2008 01:42 UTC](https://rubytalk.org/t/ruby-compiler/45329/6 "2008-03-22T01:42:39Z")

</div>

Hi,

> **···**
>
> In message "Re: Ruby Compiler" on Sat, 22 Mar 2008 09:56:28 +0900, "Park Heesob" \<phasis68@hotmail.com\> 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"?
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matz.

---

<div class="post-metadata">

**Author:** ![Park\_Heesob1](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Park\_Heesob1](https://rubytalk.org/u/Park_Heesob1)\
**Post date:** [22 March 2008 02:54 UTC](https://rubytalk.org/t/ruby-compiler/45329/7 "2008-03-22T02:54:40Z")

</div>

Hi,

> **···**
>
> ----- Original Message -----  
> From: "Yukihiro Matsumoto" \<matz@ruby-lang.org\>  
> To: "ruby-talk ML" \<ruby-talk@ruby-lang.org\>  
> Sent: Saturday, March 22, 2008 10:42 AM  
> Subject: Re: Ruby Compiler
> 
> > Hi,
> > 
> > In message "Re: Ruby Compiler" \> on Sat, 22 Mar 2008 09:56:28 +0900, "Park Heesob" \<phasis68@hotmail.com\> 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"?
> 
> 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 Heesob

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [22 March 2008 07:51 UTC](https://rubytalk.org/t/ruby-compiler/45329/8 "2008-03-22T07:51:55Z")

</div>

Hi,

> **···**
>
> In message "Re: Ruby Compiler" on Sat, 22 Mar 2008 11:54:40 +0900, "Park Heesob" \<phasis68@hotmail.com\> 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.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matz.

---

<div class="post-metadata">

**Author:** ![Park\_Heesob1](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Park\_Heesob1](https://rubytalk.org/u/Park_Heesob1)\
**Post date:** [22 March 2008 11:46 UTC](https://rubytalk.org/t/ruby-compiler/45329/9 "2008-03-22T11:46:19Z")

</div>

Hi,

> **···**
>
> ----- Original Message -----  
> From: "Yukihiro Matsumoto" \<matz@ruby-lang.org\>  
> To: "ruby-talk ML" \<ruby-talk@ruby-lang.org\>  
> Sent: Saturday, March 22, 2008 4:51 PM  
> Subject: Re: Ruby Compiler
> 
> > Hi,
> > 
> > In message "Re: Ruby Compiler" \> on Sat, 22 Mar 2008 11:54:40 +0900, "Park Heesob" \<phasis68@hotmail.com\> 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.
> 
> 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 Heesob
