News for hackers. Stuff that matters.
Re:V8 release v6.6 by jsheard on Tuesday March 27, 2018 @09:49AM (#16688293)
The TextDecoder/TextEncoder APIs are a much easier and faster way to handle WASM strings, and most browsers already support them (Edge doesn't but can be polyfilled).

https://caniuse.com/#feat=textencoder

Re:V8 release v6.6 by vanderZwan on Tuesday March 27, 2018 @01:30PM (#16690804)
Hadn't heard of those yet, thanks!

TextDecoder looks fine, but I'm a bit wary of using TextEncoder naively. It requires allocating a Uint8Array for each string. Each Uint8Array comes with 200 bytes of overhead[0]. Depending on your algorithm you can end up with thousands if not millions of tiny strings. While even phones will probably have enough RAM to handle a few hundred megabytes these days, that will slow things down simply from an allocation/garbage collection perspective.

Furthermore, typed array allocation used to be incredibly slow compared to array allocation - the gap is smaller now but it is still slow enough to be a bottle-neck in my code.

The quote below is from a V8 dev replying to someone who opened an issue about this slow allocation. It is from 2012, but it still applies:

> The reason is simply that while constructing Array is done exclusively in the Javascript virtual machine and an allocation in the VM's heap, constructing a TypedArray involves the browser binding (at least in Chrome) and allocation outside the VM's heap. The former can be properly optimized, while the latter cannot. Future optimizations in this area are already on our radar, but have rather low priority.

> Generally speaking, typed arrays are good if you want to allocate a long-living dense array with a certain type and size. Array objects are better if you want to create temporary arrays often.

I hope things will improve now that Typed Arrays finally get some proper love thanks to WASM.

[0] https://stackoverflow.com/questions/45803829/memory-overhead...

[1] https://bugs.chromium.org/p/v8/issues/detail?id=2190

[2] https://jsperf.com/typedarray-create

Re:V8 release v6.6 by bzbarsky on Wednesday March 28, 2018 @01:08AM (#16695457)
> Each Uint8Array comes with 200 bytes of overhead

In V8. I believe the overhead is a lot lower in SpiderMonkey. I can't speak for other implementations.

Re:V8 release v6.6 by vanderZwan on Thursday March 29, 2018 @03:53AM (#16705312)
That would fit my experience of TypedArrays being a lot faster in Firefox in general. Although I guess that given their early asm.js push it would make sense if they have a head-start in this domain.