Standard JSON parsers (serde_json) build the full DOM in memory.
For a 200 MB FeatureCollection this costs ~400 MB WASM heap.
This function first parses the full FeatureCollection (unavoidable with
the geojson crate), but then processes and emits features in chunks,
allowing the JS side to consume and discard coordinate data incrementally
rather than holding all coordinates in memory at once.
For true streaming (constant memory), a custom tokeniser would be needed.
This is planned for a future release using serde_json::StreamDeserializer
over raw bytes.
Parse a GeoJSON FeatureCollection in chunks, calling
on_chunkwith each batch of coordinate data and progress information.Parameters
input— The full GeoJSON string (must be a FeatureCollection).chunk_size— Number of features to process per chunk (e.g. 1000). Larger chunks = fewer JS↔WASM transitions but longer UI blocking.on_chunk— A JS callback:(coords: Float64Array, processed: u32, total: u32) => voidUsage (JS)
Design Rationale
Standard JSON parsers (serde_json) build the full DOM in memory. For a 200 MB FeatureCollection this costs ~400 MB WASM heap.
This function first parses the full FeatureCollection (unavoidable with the
geojsoncrate), but then processes and emits features in chunks, allowing the JS side to consume and discard coordinate data incrementally rather than holding all coordinates in memory at once.For true streaming (constant memory), a custom tokeniser would be needed. This is planned for a future release using
serde_json::StreamDeserializerover raw bytes.