I hope I won't be considered presumptuous, not using proper reddicette or posting against the rules of this sub but I personaly don't know a person who I could ask for advice/improvement in rust/web-assembly/JS/html. And please excuse my english, it's not my mother tongue.
I come with some Fortran/C background and have some fun with JS/html-stuff but I'm still a early learner of rust. I have troubles with traits, iterators, classes and more but I'd really like to improve.
So because I didn't really understand the whole tutorial/process of deploying the game-of-life
from the official rust codebook, I translated some fortran-code for the flux of a black hole to rust to use it in a webpage for having a GUI to mess around.
The whole I/O from the webpage to rust boils down to a function getting some input-parameters(like min/max radius of the black hole, step size, inclination etc.), like this
pub fn calcing(inc: f64, ga: i32, rmin: f64, rmax: f64, steps: i32) -> Array
and returning an JS-array from js_sys with values for calculated points for a scatter plot. In the output is the number of points in the very first place of the array and then the coordinates with the flux follow, e.g. [num_points, x1, y1, f1, x2, y2, f2, ...]. There is no wasm-bundler and just 1 I/O interface over this function. There was the thread on the rustwasm-issues at link
which helped greatly to return this kind of array with
But maybe there are better ways than my limited understanding right now.
I wanted it to be simple with the I/O (parameters -> array) at first but now after everything is working I'd like to make it better.
From my understanding this is computationaly a very intensive task by copying all the values from the array of web-assembly to the JS-engine (please correct me on this one), so how could I program this better?
Could the the wasm share memory with the JS-parts of my code, should I use structs with the three values [x, y, flux] (how would one do this in wasm context?) or should I translate the output of the function to json, return it and then treat them in JS as objects?
As the ECharts-library
I'm using now needs the data in the format of a double array of points [[x1,y1,f1], [x2,y2,f2], ...] what would be a more performant way to do this? Right now the returned array has to be looped over again for the correct format for the ECharts. (Side-note: The performance with plotly was firstly very underwhelming that's why I changed to ECharts. amCharts couln't produce reliably, with my understanding, scatterplots with color-values).
The rust-part is calculating 108000 points in about 10ms but the drawing in the scatterplot takes about 1-5s. Is there a better way to draw x-,y-coordinates to a webpage? (A bit off-topic of the sub but could I use canvas for the drawings because of webstuff? What about the coordinates with 9 decimal places, like x= 1.563653465?). Gnuplot and matplotlib arent't really faster with text-data or python-data. Should I use web-gl for this to have a better performance or something like three.js
Anyway I'm a bit lost where and how I can improve but know that there is much improvement to be made.
I set up a simple nodejs-server which serves the rust-wasm package and is controllable with a bootstrap4-interface under the url: calcbh.ddns.net
which has the first prototype of this project.
If you have the time, effort or goodwill to improve also on my basic JS-Code of the page I'm more than happy to learn something!
Thank you very much for your time and that you read all the way down!
Link to rust-calculations: Link
(the lib.rs is under 100 lines of code)
If one wants more information on the physics behind it, I happily provide it. There is a paper from the university of berne and a book from Chandrasekhar about the calculations of the geodesics of photons around a black hole.
Also if there would be a demand for the whole node-rust-code-folder and the corresponding commands: I can upload a git if one wants but I'm not really confident right now because of the quality of the codebase...
I'm a noob and a git-release-open-source is a dream right now.
For the physicists: Right now there aren't the time-delay, the GR-dopplershift and lensing-effect implemented. This will come in the next versions :D