Feature suggestion: Use symbols internally with HashWithIndifferentAccess

Currently HashWithIndifferentAccess stores using string keys, and any symbols passed in get converted to strings. As I understand it, this was due to the fact that in earlier versions of Ruby, symbols would not get garbage collected and would thus stick around for the lifetime of the process.

With Rails 5, and its minimum version requirement of Ruby 2.2.1, I don’t believe this to be an issue anymore, and symbols perform better as Hash keys.

Thank you for the suggestion? Could you explain what advantages this change will bring? I think we can change but it is a backward incompatible change and we really a good reason to do so.

In particular, it belongs to the public interface that keys are strings,
#keys, #each, etc. are guaranteed to return strings.

In 2.2 the speed of symbols and strings are much closer:


require 'benchmark/ips'

hash = {}

Benchmark.ips do |x|

x.report("symbol ") { hash[:symbol] }

x.report("string ") { hash["string"]}

end

Gives us


Calculating -------------------------------------

symbol    130.247k i/100ms

string    123.185k i/100ms