Robert K. [email protected] wrote:
So basically there will be a shared string buffer but still individual
“foo” + a + “foo”
in Ruby there were two buffers and each String literal would create a
new instance. In 2.1 there is just one buffer and still every literal
creates a new instance for every evaluation.
If I understand http://rkh.im/ruby-2.1 properly String instance
creation can be avoided by using the “freeze” modifier:
"foo"f + a + "foo"f
We dropped “f”, but “.freeze” is equivalent for compatibility with <=2.0
"foo".freeze + a + "foo".freeze
No new “foo” strings created.
Still, with the unfrozen String there is only a space gain and no
performance gain, correct?
Right, since large strings are copy-on-write.
2.2 will also reuses frozen strings for hash[“lit”] and hash[“lit”]=,
so no new strings are created for common hash get/set ops.
(r44551 + a few followup fixes)
How does that work? If I understand the diffs  properly then the
decision is made at parse time and it seems to me that it is done for
all # that fit the bill. Is that correct?
At parse time, we change the instruction from opt_a* to opt_a*_with
if we detect #[“lit”] or #[“lit”]=. #[non_lit] calls still become
At runtime, the new opt_a*_with instructions allow us to avoid
String instance creation if the receiver is a hash.