5 ms·
Brother, you are talking about one object for every byte. That is a madness. And often for no reason...you're copying or arranging bytes in lists anyway.
by paulddraper 8mo ago
Brother, you are talking about one object for every byte.
That is a madness. And often for no reason...you're copying or arranging bytes in lists anyway.
- conartist6 8mo agoThat's just how string iterators work in Javascript: one object for every byte. For now it's fast enough: https://v8.dev/blog/trash-talk https://v8.dev/blog/trash-talk. I'd put the GC overhead at around 10-15%, even with 20+ objects per byte when you add up all the stages in a real text processing pipeline. It's that cheap because the objects all have short lifespans and so they spend all their lives in the "tiny short-lived objects" memory pool which is super easy to incrementally GC. In the future it should be entirely possible for the engines to optimize even more aggressively too: they should be to skip making the object if the producer of values is a generator function and the consumer is a for loop.
- paulddraper 8mo agoOne object for every UTF-16 code unit. And yes, if that were the sole string interface, things would be very slow. String iterators are relatively less common.
- conartist6 8mo agoCode unit, yeah. Isn't for/of over an array faster than an indexed loop these days? It's fast because they took the time to optimize it.