Hacker News new | ask | show | jobs
by BeeOnRope 3021 days ago
Note that this is directly contradicted by another commnent[1] on this post, where three fixed strings are concatenated with +=, yet that was still slower.

Perhaps the use of += as separate statements is the difference, but one would hope that gc wasn't so fragile as to be unable to identify those sequences as identical.

---

[1] https://news.ycombinator.com/item?id=16533650

2 comments

The optimization made by gc is only valid for the form: s0 + s1 + .... + sn.
I suspect / understood that as being the optimization is based on the fact that those are concatenated references and not string literals.

I don't quite understand why string literals wouldn't be even easier to optimize but there it is.