shashwatak / satellite-js

Modular set of functions for SGP4 and SDP4 propagation of TLEs.
MIT License
902 stars 145 forks source link

Idea: WASM version of the library? #117

Closed 1valdis closed 8 months ago

1valdis commented 1 year ago

Since the library is 100% calculations, it looks like it would win from having a Web Assembly version. Possibly compiled from AssemblyScript. What are the community and maintainers thoughts on that?

thkruz commented 1 year ago

I started down that rabbit hole with one of my libraries, but don't have the time right now to debug whatever I was doing wrong in rust.

The main function to port into a WASM module is sgp4 since it is the one function called in a loop for most implementations. There would need to be some tweaks to its return values to remove any use of objects, but for backwards compatibility I would have the WASM return -1 for an error (as an example) and then the sgp4 function convert that into the legacy format.

You have my full support on the idea, but the harder part is finding someone with the ability to make the PR.

Edit: Lol and please don't ask ChatGPT 😉

1valdis commented 1 year ago

I proposed AssemblyScript because it's based on TypeScript which I know and use for a few years at this point; also AS project is relatively easy to setup and even learn for someone with web development background. Which is why I'm learning AS at this point. Maybe you'd rather see it written on Rust then I wouldn't help with that.

Interesting attitude towards ChatGPT 🤔 From my experience it's immensely helpful with basic to intermediate concepts where otherwise you'd have to put hours of looking at documentations and guides to learn. Of course you have to have your own head and not blindly trust everything it outputs, and it's not really helpful with advanced stuff though can suggest a right direction. I'll consider removing that section from my readme, given such a skeptical attitude 🫤

thkruz commented 1 year ago

I was using rust for no particular reason. I'd support any language that gets sgp4 to output the right answer faster. If I recall, there was a specific reason I didn't use assembly script at the time but it was long enough ago it may not be relevant anymore. I think it was still very new at the time.

I think my comment may have come off too seriously. I use co-pilot all the time and have no qualms with AI support for coding. It was just a friendly joke because I did see your other repos and due to the complexity of sgp4 it will be very hard to debug if ChatGPT writes most of the code and gets a single line slightly wrong (versus obviously wrong).

Sorry if it came off harsher than I intended. Perhaps a better wording is, "since it will take significant time to debug any issues with the math, please be upfront about what parts you wrote that heavily relied on AI for the PR".

1valdis commented 1 year ago

In case I take this, is there some set of tests that would verify that the math is correct? Maybe sets of TLE, times and expected outputs or something similar

thkruz commented 1 year ago

Yes. Take a look at https://github.com/shashwatak/satellite-js/blob/develop/test/propagation/sgp4Catalog.test.js

I wrote that after someone spotted some discrepancies with edge cases. I uploaded snapshots of the correct answers for multiple times slices across the whole catalog. If you can hijack the sgp4 function and still pass that test then you're good to go.

1valdis commented 1 year ago

I've been playing with just transforms so far and due to overhead of passing wasm/js boundary it actually makes things slower if calculating one by one. I could get them to perform equally only by combining two transforms I needed for my project (ECI to ECF to LookAngles) into one, resulting in two times less module boundary crossing. I'm planning to move sgp4 to wasm too and see how that changes things. I also plan to introduce batch calculations, for example where you load thousands of TLE in one array and one function call, so that sgp4init does the job for all satellites, and then get positions in one call, too. So that only TLE pass the module boundary and the resulting positions. I think that can result in some improvement.

TJKoury commented 1 year ago

I've had a WASM version of the Vallado code running in this app for the better part of four years: https://spaceaware.io. It used to be on Celestrak before the sponsor pulled funding.

Considering pulling out the code and making a separate library when I have the time, if it's still needed.

TJKoury commented 1 year ago

Also, if you don't mind using the Wasmer ecosystem, there's always this.

1valdis commented 1 year ago

@TJKoury very much interested in that code you mentioned.

thkruz commented 8 months ago

Since there has been no change in this discussion in 6 months I am going to close it.