Reference String Based on Instance?

At what point would you do the dictionary lookup? Any time a string object is created? That would be quite expensive. Interned objects like symbols are never garbage collected so interning all strings unconditionally would mean that we never free the storage for any string object which would be fairly impractical.

There is a package that provides an opt-in interned string type:

One possibility would be to automatically intern all sufficiently short strings. However, since a pointer to such an interned string is already 16 bytes on most systems, that solution is strictly dominated by storing short (< 16-byte) strings inline. I mentioned that previously which led @xiaodai to prototype the idea here:

1 Like