Open
Description
Frozen string literals could have pre-computed hashcodes, saving some cost when using them in Hash or similar data structures.
Currently, we have a field for a cached hash in ByteList, but that field is not used for Ruby hash calculation. So we're already paying the cost to store a cached hash, but not actually using it. Experimentally using the ByteCode cached hash makes a benchmark of Hash access almost as fast for frozen literal strings as for Symbol:
symbol 159.702M i/s - 150.472M times in 0.942205s (6.26ns/i)
dyn_symbol 153.856M i/s - 150.140M times in 0.975848s (6.50ns/i)
small_lit 68.630M i/s - 107.022M times in 1.559413s (14.57ns/i)
frozen_lit 149.703M i/s - 156.283M times in 1.043955s (6.68ns/i)
CRuby has made this optimization only for embedded (all in header) literal strings here: ruby/ruby#10596