From: Eric Wong Date: 2015-12-11T20:10:17+00:00 Subject: [ruby-core:72060] Re: [Ruby trunk - Feature #11405] [Assigned] [PATCH] hash.c: minor speedups to int/fixnum keys Yusuke Endoh wrote: > > I'm curious, how did you notice this? > > In short, I was studying hash conflicts for another reason. > > The detailed context is off topic, but you might be interested. > Though I'm not sure if this IS a problem, it was anyway fixed by nobu > at r53031 by explicitly rehashing a cdhash. Thanks, I was wondering about the reference in the r53031 commit message last night. (http://d.hatena.ne.jp/ku-ma-me/20151210) > But this behavior of st_table is not only for case statement. I could > reproduce it by normal Hash: > > h = {} > 10000.times do |n| > h[n] = true > end > 1_000_000_000.times { h[9999] } # 57.2 sec > 1_000_000_000.times { h[0] } # 89.1 sec > > I'm not sure if (and how) we should fix this. Reducing rehash > threshold would work, but it will cause frequent rehashing, which may > lead to another overhead and memory waste. Perhaps teach developers to rehash explicitly. Maybe Hash#freeze can imply rehash, too. But yes, I worry about memory increase more than speed nowadays.