fleaflet / flutter_map

A versatile mapping package for Flutter. Simple and easy to learn, yet completely customizable and configurable, it's the best choice for mapping in your Flutter app.
https://pub.dev/packages/flutter_map
BSD 3-Clause "New" or "Revised" License
2.74k stars 861 forks source link

perf: expose `isPointInPolygon` and make 40% faster (at least in JIT mode) #1907

Closed ignatz closed 3 months ago

ignatz commented 4 months ago

I mostly looked at the function because I wanted to use it myself but it was private. So I thought, if I expose it then I could at least put a ribbon on it by adding a benchmark and make it go wroom.

Before:

(duration: 0:00:05.998949, name: In circle) (duration: 0:00:06.866919, name: Not in circle)

After:

(duration: 0:00:03.649496, name: In circle) (duration: 0:00:04.611599, name: Not in circle)

Note, I opportunistically touched crs to remove the dart:ui dependency. This way it can be compiled with dart (w/o flutter) rendering the instructions in the benchmark correct again. Unfortunately, pointInPolygon is not so fortunate and needs flutter due to the dependency on ui.Offset. That's why I could only run it with "flutter test" in JIT mode.

ignatz commented 3 months ago

Sorry, I tagged on a bunch of other changes after looking a bit more at the implementation. Added a few comments. Hope it makes sense.