3 ms·
I wouldn't assume so unless you're comparing against a fairly naive JS implementation. Copying strings between JS and asm.js/wasm is slow, so there's additiona
by yoklov 9y ago
I wouldn't assume so unless you're comparing against a fairly naive JS implementation.
Copying strings between JS and asm.js/wasm is slow, so there's additional overhead just calling back and forth.
Reading through the C++ code it also uses std::string and std::map internally which are, well, somewhat slow and cache unfriendly. I'd expect the JS VM's types to generally beat these without too much effort (certainly the map, but the string depends on how its used and some other properties about it, e.g. if it's too big to fit in the small string buffer or etc).
Also, JS VMs have a much faster allocator than most malloc implementations, like the one bundled by emscripten (and this code doesn't seem to make much effort to avoid mallocs). They can/generally will implement the nursery as an arena and so you have a bump pointer allocation (which is only a small number of cycles for the common case). You pay for this later via GC, but the GC's are also fairly fast (with caveats, but I doubt they apply here for 99% of users).
TLDR: I wouldn't expect just using ASM.js or wasm to translate to a performance improvement for something like this. Of course, I could be totally wrong, but, well, there are no benchmarks...
- pizlonator 9y agoThat's a pretty good assessment. I would note that emscripten's sdk comes with a really great malloc. If you're programming in C++ with a great malloc then your memory allocation performance will be better than what you'd get on the JS side. Be weary of microbenchmarks that try to say otherwise because the reason why malloc beats GCs for real shit is that it scales better. For example, GCs get slower if the heap shape gets weird, while malloc doesn't care about that. Finally, WebKit's GC doesn't implement the nursery as an arena. I don't think that's such a popular GC technique anymore, particularly now that using non-compacting generational GCs is becoming so common.