3 ms·
I've stopped doing ruby dev, but boy do I not miss mutable strings. Javascript/Python's got that part right. String interning is a godsend.
by kentor 11y ago
I've stopped doing ruby dev, but boy do I not miss mutable strings. Javascript/Python's got that part right. String interning is a godsend.
- schneems 11y agoMutable strings are a double edged sword from a performance perspective. It sucks to have a bunch of un-needed string allocations due to string literals that are only used for one method. Sometimes though, mutating and re-using strings when possible can yield some pretty large improvements like https://github.com/mime-types/ruby-mime-types/pull/93 https://github.com/mime-types/ruby-mime-types/pull/93. I would love to read a post written in simple(ish) terms about how V8 handles string allocation and what string performance optimizations helped the most. Would be really neat to see it compared to python/ruby/etc. It's also worth noting that the majority of the speed here comes from getting rid of hash and array allocations. The bulk of the object count came from string savings but the bulk of the "memory" came from more complex objects.
- tekknolagi 11y agoYou can do string interning with Ruby. You just use symbols.
- kentor 11y agoNo. String#freeze exists for a reason.