Another Obscure Node.js performance tip on the topic of working with large strings... The v8 engine uses several different *types* of Strings internally. The v8 optimizer optimizes functions based, in part, on the types of objects... depending on how you're using strings...
... can and will deoptimize it's *own built in functions* that work with strings, causing those to switch to the dreaded "megamorphic" status -- yielding a significant drop in performance. You'll see this most commonly in the String.prototype functions...
... This effect can be seen most prevalently in compiler type tools like Typescript, and in React server-side rendering processes involving a lot of string manipulation. There's not much you can do about it but it is worth being aware of!
You can follow @jasnell.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: