Re:How we made JSON.stringify more than twice as fast
by taeric on Tuesday August 05, 2025 @03:03PM
(#44802691)
I don't view that as a side effect? That is, computed fields are not necessarily side effects, are they? I was thinking more like objects that keep track of how many times they were accessed. (This pattern was discussed recently for python dicts.)
I'm sure there are plenty of other similar uses that I just don't know about.
That said, if this is really included computed fields, that seems far broader.
That getter looks inoffensive and will, depending on your requirements, work just fine. But it has side effects because the string interpolation allocates and could trigger a garbage collection.
Note that if you're using modern JS 'class' blocks a 'get x ()' will be ignored by JSON.stringify, so if you're aiming to reproduce this you have to use old-school Object.defineProperty instead.