Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] WASM implementation..? #552

Open
joex92 opened this issue Aug 28, 2021 · 5 comments
Open

[Question] WASM implementation..? #552

joex92 opened this issue Aug 28, 2021 · 5 comments

Comments

@joex92
Copy link

joex92 commented Aug 28, 2021

Hi!
Many of my projects require fast calculations or a lot of calculations on a loop, so I was wondering:
Have you considered on implementing the use of WASM for performance?

I'm kind of new on WebAssembly and I still don't know how much can be processed from js on assembly, so I'm just wondering if it's possible and would it give Two.JS projects a better performance? What methods or calculations on Two.JS could be implemented on WASM?

@jonobr1
Copy link
Owner

jonobr1 commented Aug 30, 2021

I've only had experience compiling C++ libraries into WASM so you can access libraries that don't currently have JavaScript implementations. Would be curious to learn more about how you think WASM could be helpful.

@joex92
Copy link
Author

joex92 commented Aug 30, 2021

As far as I know things that doesn't interact with the DOM elements can be implemented in WASM, idk, maybe the calculations done for SVG elements, Idk what methods or calculations on Two.JS doesn't interact directly with the DOM...

@jonobr1
Copy link
Owner

jonobr1 commented Aug 30, 2021

Given this article I think there's reason to believe WASM would give ~30% performance improvements. The management of the scenegraph and all the calculations associated with it would be able to be put on the WASM, but would still need to eventually draw everything back to an SVG or Canvas. My guess is that the biggest performance improvements would come from memory management, because the JS garbage collector is hard to manage (and I'm likely doing a terrible job at managing). Definitely something worth tracking! Thanks.

@joex92
Copy link
Author

joex92 commented Aug 30, 2021

Actually memory management I believe is one of the biggest issues in JS, specially when dealing with projects with lots of calculations and many many variables... I've test some things (with different libraries) and in the beginning the page goes fine but over time it lags a lot... I believe is worth trying to implement WASM...
Also WASM is like the future of web programming, at least I see it that way, depending on the uses it could bring up a lot of performances to the code... But I'm still a bit confused of how to use it, I have just used some wasm/js libraries, like p5wasm with p5 (I used to use p5 a lot, still use it, but then I found two.js), and I have noticed the performance when doing calculations on loop... so yeah... I wish I could bring up some useful help about it, like some coding examples, but I still don't understand it well enough, I need to study it and practice on it more, I'm basically re-learning coding after years of a "coding hiatus"...

@jonobr1
Copy link
Owner

jonobr1 commented Jul 5, 2022

AssemblyScript suggests that it would be possible to simply pass the already defined functions in JavaScript and compile them as WASM binaries: https://www.assemblyscript.org/compiler.html#host-bindings

In this possible use case the SVG interpret functions could be applied this way, though some modifications would be made to make compatible export objects / functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants