Optimization thought...

15 views
Skip to first unread message

Roger Pack

unread,
Dec 22, 2009, 7:30:49 PM12/22/09
to ruby-opt...@googlegroups.com, rubini...@googlegroups.com
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

Reply all
Reply to author
Forward
0 new messages