From: Eric Wong Date: 2014-01-03T08:51:27+00:00 Subject: [ruby-core:59506] Re: [ruby-trunk - Feature #8998] string keys for hash literals should use fstrings > * Should string freeze-duping in Hash#[]= always dedup, regardless of > whether the string has already been frozen or the Hash has > compare_by_identity == true? Or else what combination of those > conditions should lead to deduping? MRI doesn't replace/alter the key at all if compare_by_identity is true. Thus keys remain mutable strings in the case of compare_by_identity. Also, in my original proposed patch, it only deduped when a new frozen string was required, so there's almost zero chance of incompatibility. Pre-frozen strings are used as-is when used as keys in all cases. Btw, in addition to the current optimization and in lieu of my original patch, I also have a proposed patch in https://bugs.ruby-lang.org/issues/9188 which also optimizes aref along with aset only when literal strings are used. This means we won't bust the fstring cache with dynamically-generated strings, but string literals in the source are not duplicated. I'm not sure what the real-world performance impact is, but I suspect Rails apps will benefit from that.