It took me so many years to stop building arrays of strings & using .join("") at the end; dozens of coworkers asking what the heck I was doing. It was just so so so much faster for so long! At a time when it mattered, that I kept at it.
Really interesting discussion here on revising the optimizations around this. Over-allocating is probably a pretty good idea! The author here seems pessimistic about static analysis to check for use, but it feels like a over-allocate default, maybe detect some easy non-changing strings via static analysis would be fine?
I felt pretty so so about the arguments against cons strings, until the last one:
> When adding to strings a few characters at a time, the size of the cons strings (20 bytes) dwarfs the amount of text being added, and the cons tree can have a size in memory that is easily an order of magnitude larger than the flat string would be.
Really interesting discussion here on revising the optimizations around this. Over-allocating is probably a pretty good idea! The author here seems pessimistic about static analysis to check for use, but it feels like a over-allocate default, maybe detect some easy non-changing strings via static analysis would be fine?
I felt pretty so so about the arguments against cons strings, until the last one:
> When adding to strings a few characters at a time, the size of the cons strings (20 bytes) dwarfs the amount of text being added, and the cons tree can have a size in memory that is easily an order of magnitude larger than the flat string would be.