geo
geo copied to clipboard
Experiment with wasm bindings for rust-geo
We could use https://github.com/rustwasm/wasm-bindgen to create a JavaScript library that utilizes rust-geo via wasm. Could be fun to see how performance compares to libraries like Turf.js
Related to using rust-geo with wasm (at least as a dependency), spade is currently on v1.5.1, which depends on the now deprecated rustc-serialize through num=0.1. The num dependency has been updated, and from https://github.com/Stoeoef/spade/commit/4dc1f7f190e4bc0bdff5e59592c2001e2b4fca32, it looks like a version change is all it took.
If and when spade releases an update, it would probably become possible to use geo with wasm projects.
I just published Spade v1.6.0, which should by default use num version 0.2.0 .
Related to this, I used rust-geo and the r-star crate to make a site that does point in polygon aggregation in the browser really quickly using WASM.
code: https://github.com/stuartlynn/wasm_geo_agg live demo: https://stuartlynn.github.io/wasm_geo_agg/
It's surprisingly fast and I think there is a lot of other usecases that can be supported by more generally exposing the rust-geo ecosystem to the browser through WASM.
@stuartlynn nicely done! I am currently working on something very similar. I am implementing the same interface as this function http://turfjs.org/docs/#pointsWithinPolygon and benchmark GeoRust WASM vs Turf.js using benchmark.js. I was planning on writing a blog post about it actually. Will definitely credit and link to you your demo and github.
Thanks! Would be very interested in seeing those benchmarks. A rust-geo backed port of turf would be really cool. One thing I am curious about is how to handle large datasets like the 2Gb taxi pickup table I was playing with. My instinct was to keep the data in memory mostly on the WASM side to avoid continually transporting lots of data back and forth between JS and WASM. I know that can incur a pretty big penalty. Be interested in how that plays out in the benchmarks.
I'd be really interested in seeing some benchmarks too…
Here is my crate, although be warned it's likely amateurish and un-idiomatic 😄
https://github.com/guidorice/points-within-polygons
I was hoping for 10X faster than JavaScript across the board, but alas. The good news is there are six benchmark datasets and Rust was faster in 5/6 of them. It also seems to have a nice scaling pattern where the more points you throw at it, the better it does. The algorithm is very sensitive to the complexity of the polygons as you can see.
I am going to write a blog post about it. Mostly exploring what it's like to learn Rust, and my approach to this particular experiment. And acknowledging that it could be optimized quite a lot, for example by using a Rtree as in Stuart's wasm_geo_agg crate. Or even further by parallelizing it, when wasm-bindgen gets support for WebWorkers. There are a few papers floating around about parallel PIP algorithm. Maybe it will become 3 part blog series. 💭
Nice. Will check it out. My code was similarly pretty amateurish :-) Yeah I think the main wins here are going to be when you have a lot of data. I might try and benchmark the r-tree + point in poly approach in JS vs Rust to see how it scales as you add more points / polygons. Will keep you posted if I get any interesting results.
Looking forward to reading the blogs and let me know if there is anything I can do to add to them!
I'm going to close this since there's nothing really actionable here. If you want to see geo in use in wasm, check out https://rgis.app (https://github.com/frewsxcv/rgis)