From: Ryan Davis Date: 2007-10-04T05:19:22+09:00 Subject: Re: hash key performance On Oct 2, 2007, at 23:46 , Matthias W��chter wrote: > On 02.10.2007 16:55, Marcin Miel��y��ski wrote: >> Matthias W��chter wrote: >> >>> But here it comes: Using false and, even worse, nil (in either >>> literal or variable form) is way slower (a good 20%) than using >>> integers and symbols, even if they follow the same "immutable >>> object" philosophy of fixed object_ids. >>> >>> Why is that? What's so special about false and nil to have such a >>> degraded performance as a hash key? >>> >> >> hash.c:rb_any_hash is the answer to your question (funcall('hash') is >> discarded only for Fixnums, Symbols and Strings. > > So the first two cases of "switch (TYPE(a))" should be enhanced with > checks for nil, true and false like this: > > switch (TYPE(a)) { > case T_FIXNUM: > case T_SYMBOL: > + case T_NIL: > + case T_FALSE: > + case T_TRUE: > return (int)a; > break; Send that and your original timings to ruby-core@ and/or file a bug on rubyforge in the ruby project.