Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Jun 6, 2024

Conversation

ignatz
Copy link
Contributor

@ignatz ignatz commented Jun 5, 2024

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.

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.

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.
@JaffaKetchup JaffaKetchup changed the title Make isPointInPolygon 40% faster (at least in JIT mode). perf: make isPointInPolygon 40% faster (at least in JIT mode) Jun 6, 2024
@JaffaKetchup JaffaKetchup changed the title perf: make isPointInPolygon 40% faster (at least in JIT mode) perf: expose isPointInPolygon and make 40% faster (at least in JIT mode) Jun 6, 2024
Copy link
Member

@JaffaKetchup JaffaKetchup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, apart from one thing. Thanks!
In general in the past we've tried to avoid becoming a toolbox for these kinds of things, but seeing as we've recently exposed the simplification tools, I don't really have an issue this.

benchmark/point_in_polygon.dart Outdated Show resolved Hide resolved
lib/src/misc/point_in_polygon.dart Outdated Show resolved Hide resolved
lib/src/misc/point_in_polygon.dart Outdated Show resolved Hide resolved
lib/src/layer/polygon_layer/painter.dart Show resolved Hide resolved
lib/src/layer/polygon_layer/painter.dart Show resolved Hide resolved
lib/src/layer/polygon_layer/painter.dart Show resolved Hide resolved
@ignatz
Copy link
Contributor Author

ignatz commented Jun 6, 2024

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.

…Polygon inputs. Would have caught previous misuse.
Copy link
Member

@JaffaKetchup JaffaKetchup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks :)

@JaffaKetchup JaffaKetchup merged commit c321865 into fleaflet:master Jun 6, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants