Skip to content

perf: add cached CRS variants and benchmarks - #2188

Open
Brijesh-gangwar wants to merge 5 commits into
fleaflet:masterfrom
Brijesh-gangwar:perf/cache-zoom-scale-crs
Open

perf: add cached CRS variants and benchmarks#2188
Brijesh-gangwar wants to merge 5 commits into
fleaflet:masterfrom
Brijesh-gangwar:perf/cache-zoom-scale-crs

Conversation

@Brijesh-gangwar

Copy link
Copy Markdown

fixed #2183

@JaffaKetchup
JaffaKetchup requested a review from a team April 13, 2026 20:28
@JaffaKetchup

Copy link
Copy Markdown
Member

Thanks for submitting this! It looks good so far, although we'll need to look into the API just a little more. Sorry it's taken so long to acknowledge!

@Brijesh-gangwar
Brijesh-gangwar force-pushed the perf/cache-zoom-scale-crs branch from d10aa08 to 4fd8f05 Compare April 30, 2026 05:15
@Brijesh-gangwar

Copy link
Copy Markdown
Author

@JaffaKetchup Thanks for the review. I’ve addressed your feedback and pushed an update.
PR #2188 failed because Analyze Code reported must_be_immutable in lib/src/geo/crs.dart: cached CRS classes had mutable mixin fields.
Fix in commit b05303e: replaced mutable mixin fields with Expando<_ScaleZoomCache> (external per-instance cache) and added missing constructor docs.
Local result: dart analyze --fatal-infos --fatal-warnings now passes for crs.dart and the immutability issue is resolved

@JaffaKetchup
JaffaKetchup requested review from a team and removed request for a team September 3, 2026 21:47

@JaffaKetchup JaffaKetchup left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey, sorry this has taken so long to get around to.

While it makes sense that there is a saving to be had here in theory, I can't seem to actually reproduce that saving practically.

I've copied the benchmark into a small Flutter app here that I've then built as a windows app in release mode, and run it. Here's the results after running it twice:

Results:
(duration: 0:00:01.877254, name: Concrete type: EPSG:3857.latLngToXY())
(duration: 0:00:01.842099, name: Concrete type (cached): EPSG:3857.latLngToXY())
(duration: 0:00:01.853412, name: Concrete type: EPSG:3857.latLngToOffset())
(duration: 0:00:02.739893, name: Concrete type (cached): EPSG:3857.latLngToOffset())
(duration: 0:00:03.944211, name: EPSG:3857.latLngToXY())
(duration: 0:00:04.187178, name: EPSG:3857.latlngToPoint())
(duration: 0:00:03.631236, name: EPSG:3857.pointToLatLng())
(duration: 0:00:03.960620, name: EPSG:3857 (cached).latLngToXY())
(duration: 0:00:12.264181, name: EPSG:3857 (cached).latlngToPoint())
(duration: 0:00:06.545066, name: EPSG:3857 (cached).pointToLatLng())
(duration: 0:00:01.981328, name: EPSG:4326.latLngToXY())
(duration: 0:00:02.333006, name: EPSG:4326.latlngToPoint())
(duration: 0:00:01.039483, name: EPSG:4326.pointToLatLng())
(duration: 0:00:01.794606, name: EPSG:4326 (cached).latLngToXY())
(duration: 0:00:03.126626, name: EPSG:4326 (cached).latlngToPoint())
(duration: 0:00:01.443465, name: EPSG:4326 (cached).pointToLatLng())

Results:
(duration: 0:00:01.982466, name: Concrete type: EPSG:3857.latLngToXY())
(duration: 0:00:01.908172, name: Concrete type (cached): EPSG:3857.latLngToXY())
(duration: 0:00:01.873510, name: Concrete type: EPSG:3857.latLngToOffset())
(duration: 0:00:02.677458, name: Concrete type (cached): EPSG:3857.latLngToOffset())
(duration: 0:00:04.010353, name: EPSG:3857.latLngToXY())
(duration: 0:00:04.265552, name: EPSG:3857.latlngToPoint())
(duration: 0:00:03.749994, name: EPSG:3857.pointToLatLng())
(duration: 0:00:04.039208, name: EPSG:3857 (cached).latLngToXY())
(duration: 0:00:04.681983, name: EPSG:3857 (cached).latlngToPoint())
(duration: 0:00:03.934013, name: EPSG:3857 (cached).pointToLatLng())
(duration: 0:00:02.063724, name: EPSG:4326.latLngToXY())
(duration: 0:00:02.350731, name: EPSG:4326.latlngToPoint())
(duration: 0:00:01.015305, name: EPSG:4326.pointToLatLng())
(duration: 0:00:01.944075, name: EPSG:4326 (cached).latLngToXY())
(duration: 0:00:02.937107, name: EPSG:4326 (cached).latlngToPoint())
(duration: 0:00:01.399678, name: EPSG:4326 (cached).pointToLatLng())

As you can see, the cached versions are usually just as good or worse than the non-cached versions. I'm not fully convinced where the savings from #2183 (comment) were found?

I wonder if this is a case where the theoretical savings are much larger than any real savings?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve performance of CRS zoom & scale methods

3 participants