flutter_map
flutter_map copied to clipboard
[FEATURE] Use classes instead of `Record`s for efficiency
The research in https://github.com/fleaflet/flutter_map/pull/1750#issuecomment-1846490749 and https://github.com/fleaflet/flutter_map/pull/1750#issuecomment-1847661696 points out the reasons to avoid records. Records have no advantage on memory consumtion while they require about double the time to be initialized.
As a consequence we should remove records from the package and use immutable classes in favour of it.
@josxha That would include this one in Projection:
(double, double) projectXY(LatLng latlng);
Would definitely be a breaking change, but would hopefully bring better performances. Something like that?
DoublePoint projectDoublePoint(LatLng latlng);
Instead of redundant code like this one:
_ProjectedPolygon._fromPolygon(Projection projection, Polygon<R> polygon)
: this._(
polygon: polygon,
points: List<DoublePoint>.generate(
polygon.points.length,
(j) {
final (x, y) = projection.projectXY(polygon.points[j]);
return DoublePoint(x, y);
},
@josxha For the record I've just tried to replace (double, double) methods with Offset in class Crs (which eventually impacted a dozen of classes).
I cannot say that there was that much impact on performances using Offset instead of (double, double), in a first approach, using the "Polyline Stress Test" in profile mode (raster then UI, in ms):
| x | old solid algo | new solid algo |
|---|---|---|
| offset | 203.4 + 43.6 | 556.2 + 54.6 |
| (double, double) | 206.2 + 42.1 | 578.9 + 53.2 |
For next tests:
profilemode- "Polyline Stress Test"
- zoom 5 times around "Valence, France"
- slider to the left
Something like that:
I will say that I don't think this is top priority. This is quite a level of micro-optimization!