Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Function calls are expensive inside hot loops, that's why we rely on compilers to do inlining and unrolling optimizations for us. I don't think that's possible in that example, you should write the loop in C and return the data you expect instead of writing the loop in JS and calling tiny functions that will never be inlined.

For what it's worth, (scalar) numerical operations in JS are actually quite close to C. It's not like python.



Ah, I'm such an idiot for not thinking of inlining!

The problem with writing the loop on the WASM side is that passing the data back and forth between JS and WASM involves typed arrays and array buffers. That has significant overhead of its own. Still, good suggestion, I should try that with a pixel buffer!

> For what it's worth, (scalar) numerical operations in JS are actually quite close to C. It's not like python.

Indeed, and I am generally very impressed and happy with the performance of JavaScript these days! In my experience it only takes a little bit of effort to hint at the compiler if we're working with doubles or 32 bit integers, and then it goes really fast. In this particular case however we needed 64 bit integer arithmetic, so that's a bit of an edge-case.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: