3 ms·
> They're just not especially performant What? Mutable strings are more performant generally. Sometimes immutability allows you to use high level algorithms th
by IshKebab 1y ago
> They're just not especially performant
What? Mutable strings are more performant generally. Sometimes immutability allows you to use high level algorithms that provide better performance, but most code doesn't take advantage of that.
- vnorilo 1y agoNot in general. Immutable strings can be deduplicated, leading to a different performance tradeoff that is often quite good. This is mentioned in TFA.
- IshKebab 1y agoMutable strings can be duplicated too. You can use reference counting, or borrow checking in Rust.
- spankalee 1y agoMutable string literals can't be easily deduplicated, unless your language semantics are that a literal is a singleton and all mutations are visible by all other evaluations of that literal. But no sane language would do that.
- johncolanduoni 1y agoIf the strings are backed by reference counted buffers, you can use copy-on-write semantics to provide the API of a mutable string but share buffers when a string is copied. Most C++ standard libraries actually did this prior to the multicore era.
- johncolanduoni 1y agoIt’s worth noting that C++ standard libraries have mostly moved away from copy-on-write strings, due to their poor performance in multithreaded scenarios. And JavaScript engines have ended up adding a bunch of optimizations that simulate mutable strings in certain common scenarios. It depends on what the code in question is doing, and I think the ideal scenario is to allow both in different contexts as long as they can be kept distinct.