3 ms·
I always forget that about ruby strings. However, I’m not sure I can think through how it changes the performance trade offs of sharing.
by hyperpape 9y ago
I always forget that about ruby strings.
However, I’m not sure I can think through how it changes the performance trade offs of sharing.
- aardvark179 9y agoWell, if strings are immutable then you can point into an array in the subsrring and the worst that can happen is a space leak. If your strings are mutable then you need some extra book keeping so that attempts to copy the parent or child won’t affect the other. Whether you get a gain from sharing is going to depend on the length of your strings and what operations you perform on them. If you are trying to reimplement an existing VM/standard library then you may also need to honour the expectations of developers. If they expect creating a substring to be an O(1) operation and code against that expectation then you probably need to honour it.