From: "Matthias Wächter" Date: 2007-10-03T15:46:26+09:00 Subject: Re: hash key performance 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; Objections? - Matthias