Hi Roger,

We actually already do this in Rubinius, but we do it in the JIT directly. It's 
far less problematic than generating C code that you have to figure out how to 
link back in, plus we can inline methods, all that without loosing any 
backtrace information.

We already don't need the user to specify that they're done setting things up, 
as the JIT can run when it wants and the system can gracefully degrade should 
any JIT assumptions be invalidated by a user adding a new method or class.

Lastly, your technique looks pretty much like a normal inline cache, which is 
also something Rubinius has. We don't currently push them down into the 
execution stream like you have here, because we use them the interpreter as 
well.

 - Evan

On Dec 22, 2009, at 4:30 PM, Roger Pack wrote:

> After experimenting a bit with the ruby2cext/crystalizer [1] I'm
> wondering if what it does wouldn't be a good match for Rubinius...
> 
> its biggest niche is if you can rely on the end user to call this at some 
> point:
> 
> VM.done_setting_up_classes_forever!
> 
> This allows you to cache all the method call lookups at each callsite, i.e.
> 
> def go a
> a.yo 3
> end
> 
> => translate to C
> 
> VALUE cached_previous_yo_class;
> VALUE cached_previous_yo_method;
> 
> VALUE yo(self, a) {
>  if a.class == cached_previous_yo_class
>     *((func *)cached_previous_yo_method)(a, 3); // doing this call in
> C is *so* much faster...though it loses backtrace info.
>  else
>     //lookup the method, cache it for next time.
>  end
> }
> 
> This type of translation can speedup Ruby 1.8 quite a bit [like 5x the
> speed of 1.9, on the tak benchmark], and should work well  with
> Rubinius, since so much of Rubinius is Ruby.  It would probably not
> save much if you used tons of duck types, but in practice cache misses
> are rare, or could be alleviated.
> 
> Anyway just thinking out loud.
> 
> I might port this to rubinius after first porting it to 1.9.  In the
> meantime if somebody's interested feel free to use the idea/code.
> Cheers!
> -r
> 
> [1] http://github.com/rdp/crystalizer
> ML:  http://groups.google.com/group/ruby-optimization
> 
> -- 
> --- !ruby/object:MailingList
> name: rubinius-dev
> view: http://groups.google.com/group/rubinius-dev?hl=en
> post: [email protected]
> unsubscribe: [email protected]
> 

-- 
--- !ruby/object:MailingList
name: rubinius-dev
view: http://groups.google.com/group/rubinius-dev?hl=en
post: [email protected]
unsubscribe: [email protected]

Reply via email to