From: Eric Wong Date: 2011-09-19T17:23:49+09:00 Subject: Re: Ruby Speed Question Josh Cheek wrote: > On Mon, Sep 19, 2011 at 2:48 AM, Robert Klemme > wrote: > > On Sun, Sep 18, 2011 at 8:42 PM, Josh Cheek wrote: > > > > > Some reasons differences between the Ruby and Java versions are that Ruby > > > doesn't have primitives, so all those numbers are objects (ie using > > Java's > > > Integer rather than int). > > > > This is not 100% true. While they are from a language user's > > perspective under the hood there are some optimizations especially for > > Fixnums. This still leaves overhead for method invocation but memory > > usage is very low and there is no GC overhead. On YARV, method invocation is inlined for common operations on basic types, including simple Fixnum arithmetic (see insns.def). > I've had people say this to me in the past, but I don't understand how this > can be, given that I can set instance variables on Fixnums: > > 1.class # => Fixnum > 1.instance_variable_set :@abc, 12 > 1.instance_variable_get :@abc # => 12 Ruby stores ivars for immutable object types (e.g. Fixnum/Symbol) in external hashes (see generic_ivar_* in variable.c for ruby/trunk).