
How to achieve 218.1% better performance when replacing strings in JavaScript - piyiotisk
https://picocoder.io/how-to-replace-all-occurrences-string-in-javascript/
======
_bxg1
Split and join is worse because it allocates N junk strings, all of which have
to be fully copied only to be copied again and then thrown away. This is the
same problem as the "Array.push() is 945x faster than Array.concat()" post
from last week:
[https://news.ycombinator.com/item?id=19991339](https://news.ycombinator.com/item?id=19991339)

As I commented on the other post, all programmers really should spend some
time learning how memory, pointers, data structures, heap vs stack, etc. work.
Even if you aren't writing C++ at your day job, that stuff matters.

------
Bino
Why would anyone use split/join?

~~~
piyiotisk
Maybe that’s what some people use. For example deepcloning objects in JS is
faster with json.parse(json.stringify())

