maplibre / flutter-maplibre-gl

Customizable, performant and vendor-free vector and raster maps, flutter wrapper for maplibre-native and maplibre-gl-js (fork of flutter-mapbox-gl/maps)
https://pub.dev/packages/maplibre_gl
Other
186 stars 106 forks source link

Performance issue - Main isolate is blocked when encoding geojsonFeature #366

Open T-moz opened 5 months ago

T-moz commented 5 months ago

Before sending geojsonFeature through the method channel, the data is encode. Ex: Untitled-8

the function jsonEncode is synchronous, and if the is a lot of data, like a line of 40k points, the main isolate can be blocked.

This can lead to a UI freezed of n-seconds on the Flutter side.

See FlameChart:

Untitled-9
m0nac0 commented 5 months ago

A spontaneous idea (not saying this is necessarily better, but might be simpler): could we just expose an ("advanced") variant of the method that accepts a pre-encoded string, such that library consumers can decide how they want to do the json encode (e.g. on another isolate)

T-moz commented 5 months ago

A spontaneous idea (not saying this is necessarily better, but might be simpler): could we just expose an ("advanced") variant of the method that accepts a pre-encoded string, such that library consumers can decide how they want to do the json encode (e.g. on another isolate)

Yes this would also work, and I don't see any performances differences between the two solutions. I think the direction we have to choose is how do you want the FlutterMaplibre API to be design.

My point of view, is that the package maplibre_gl should be a "deep module". Which means that the API exposed should not be very wide, and should handle most of the complexity.

T-moz commented 5 months ago

Should it be a large API, with many optimised and specialised methods ? (like updateLine and updatesLines).

I even think that updateLine can be remove and replace by updateLines. Package's users could still update one line, and they would be encourage to batch updates.

The same goes for other methods.

T-moz commented 5 months ago

@m0nac0 I'm staring to think that your idea is better. Because jsonEncode takes time, but decoding a polyline string, then adapting to latlng, and then converting to geojson also takes a lot of time.

Package user that display list of complexe polylines, should be able to do all that with one compute. And for that, the package needs to expose a lowLevel method, that accept encodedGeoJson.

I will try to expose a method addEncodedGeoJsonSource 🤞