Open frewsxcv opened 3 years ago
Spawned from this discussion: https://github.com/georust/geojson/pull/151#discussion_r535670765
I'm interested in looking into this. It looks like flattening the map from Value
into Geometry
might be a bit tricky, but I can open up an initial PR for feedback on that
want to build up a use
serde::ser::SerializeMap
I'm not very familiar with serde. It seems like this would also be a bunch of allocation? I was hoping for some kind of "visitor" pattern which avoid allocating anything per-geometry, but I don't know what's possible.
maybe relevant: https://serde.rs/stream-array.html
Currently, our
serde::Serialize
implementations build up aJsonObject
(aserde_json::Map
) that gets serialized by Serde, and then gets thrown away. Building up aJsonObject
causes new allocations to happen, including cloning all coordinates.Instead of building up a
JsonObject
, we should be able to use the serialization methods provided byserde::Serialize
directly. For reference, here's theserde::Serialize
implementation forserde_json::Value
which may be helpful. In particular, we'll probably want to build up ause serde::ser::SerializeMap
.After it's done, we should benchmark the performance. We currently only have a parsing benchmark, so we should create a new one for writing GeoJSON.