georust / geo

Geospatial primitives and algorithms for Rust
https://crates.io/crates/geo
Other
1.48k stars 191 forks source link

Remove `clone` in geometry trait implementation #1121

Closed kylebarron closed 7 months ago

kylebarron commented 7 months ago

I struggled with this initially because I thought I had to implement Iter in terms of Self::ItemType, which resulted in a double &&Self::ItemType.

In geoarrow-rs this resulted in a massive speedup (see https://github.com/geoarrow/geoarrow-rs/pull/278#issuecomment-1829024334) for converting geo objects to geoarrow (which is entirely implemented on top of these traits):

convert Vec<geo::Polygon> to PolygonArray
                        time:   [31.564 µs 31.608 µs 31.661 µs]
                        change: [-52.414% -52.271% -52.131%] (p = 0.00 < 0.05)
                        Performance has improved.

In the short term, in geoarrow-rs this also means all algorithms that result in geometries will get faster (though this probably isn't a huge part of the overall time) because currently all algorithms are implemented by converting each geometry to geo, applying the operation, and converting the output vec back to geoarrow.