flutter_map icon indicating copy to clipboard operation
flutter_map copied to clipboard

[FEATURE] Use classes instead of `Record`s for efficiency

Open josxha opened this issue 1 year ago • 7 comments

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 avatar Dec 10 '23 14:12 josxha

@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);
            },

monsieurtanuki avatar Apr 28 '24 14:04 monsieurtanuki

@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:

  • profile mode
  • "Polyline Stress Test"
  • zoom 5 times around "Valence, France"
  • slider to the left

Something like that: Screenshot_20240507_131710

monsieurtanuki avatar May 07 '24 11:05 monsieurtanuki

I will say that I don't think this is top priority. This is quite a level of micro-optimization!

JaffaKetchup avatar May 16 '24 19:05 JaffaKetchup