[MacRuby-devel] Macruby 10x slower than built-in Ruby for my script
Laurent Sansonetti
lsansonetti at apple.com
Wed Jul 1 12:03:25 PDT 2009
Hi,
On Jul 1, 2009, at 8:23 AM, Jjgod Jiang wrote:
> Hi all,
>
> On Wed, Jul 1, 2009 at 9:26 PM, zhida cheng<vorbei at gmail.com> wrote:
>> But in this very simple (I think) script, Macruby is 10x slower than
>> built-in Ruby in OSX 10.5.7
>> It's for reading atom positions, calculating distances, make a
>> summary and
>> find out nearest atoms.
>> You can get the codes here: http://gist.github.com/138760
>
> I'd like to confirm this report with two Shark profiling results:
>
> http://omploader.org/vMXducQ/macruby.mshark (Running the ruby
> program dist.rb
> given by Zhida with macruby, trunk version)
>
> http://omploader.org/vMXdudQ/ruby.mshark (Running the ruby program
> dist.rb
> given by Zhida with ruby, the version shipping with Mac OS X Leopard)
>
>> From the first result, we can see most of the time is spent on
>> libauto.dylib,
> the garbage collector library, especially spinlocks in that library.
> I suppose
> that may be a direction for optimization?
I didn't look at the shark profiling results but I am pretty sure the
problem here is because we need to box the fixnums in order to insert
them into collections (NSArray), because NSArray expects true
Objective-C objects and fixnums are immediate types. This means a call
to the object allocator and a call to the GC to set the write barrier
for every object insertion.
We have a plan to fix this in experimental, it's in our TODO list. The
idea is to make a specialized subclass of NSArray / NSDictionary only
for pure Ruby use, where the elements can be immediate. We should then
have much better performance results (close to 1.9 maybe).
Laurent
More information about the MacRuby-devel
mailing list