Closed pouyakary closed 2 years ago
In the other hand I don't know if that is worth the shot of it but you know...
Hey! It's a good idea, and it technically feasible, but might be a little difficult to actually do. Basically we would need to rewrite all the code you pasted in the style of the functions defined in this file. There may be some mechanisms to simplify or semi-automate this process, but it will probably require some non-trivial work.
Additionally, it will somewhat increase the size of the compiler itself (which must be downloaded by each user). Probably this is worth it if we can get a meaningful performance improvement.
However, the performance win may not be as obvious as it would seem. It's true the calling out to JavaScript incurs some overhead, but the JavaScript implementation of sin/cos/etc might be faster than their Wasm equivalent (since wasm is slower than native code).
So, I think the next step would be to do a performance benchmark to measure how much faster a pure Wasm version is.
If you're interested, that would mean, writing a Rust module that computes the sin/cos/etc of a large number of values (say, 5,000) and we can compile that to Wasm and measure how fast/slow it is. We can then compare that to the current version of eel-wasm which uses the JS sin/cos/etc functions.
If the result is that the pure Wasm version is much faster, we can explore various methods to try to embed the Wasm implementations in the compiler.
Thanks for opening the issue! It sounds interesting.
That actually is a good idea... I'll do that :)
These past few days I was tasked with making a new programming language and I it needed to be really fast. so you can read my mind here. One thing I instantly realized was the lack of native math in the WebAssembly which is a huge bottleneck. So as you do it here by providing external JS Math Lib, it can work but it still needs to call JS.
I was thinking... And then did something... I created a very simple rust program:
And compiled it to WebAssembly with all the code cleanup flags. Then I used the
wasm2wat
from the wabt and searched for the beautiful f64 sin. Here it is!I wish I had the slightest idea how it does it, but who cares it is the Rust math library compiled by the LLVM how better that this can we implement a sin? Question is how can we put this into our compile architectures? If that be answered, then I guess we can one by one replace JS math tools in our compilers. And I guess EEL-Wasm can have so much boost from this