-
-
Notifications
You must be signed in to change notification settings - Fork 866
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
Map gets super laggy when there are a lot of Markers #824
Comments
My workaround to this issue was filtering markers based on current map boundaries. |
Wait, how couldn't I see this before: In whole loop we: flutter_map/lib/src/layer/marker_layer.dart Lines 131 to 142 in f09b193
Same @robertpiosik this diservers much more than a workaround 😳 Edit: Yes, I was able to go from 30->15ms just by moving |
Yes, that's possibly a good optimisation. Thinking out loud, I'm actually wondering if that could be cached for each zoom level, as we're possibly doing the same map project for each point/zoom each frame ? (would need to verify and test that) |
@ibrierley a zoom level is a double, soooooo I don't know how this would go... But, even caching it until zoom changes would be better than nothing... |
Just thinking out loud a bit more on other optimisations (unfortunately I'm not near a PC I can test on flutter_map for a while), if bounds checking is optimally being done the wrong way around...currently we project every marker point, take the width/height, and do a basic boundary check. The slow bit being the project ? Could we do the boundary checking on latlongs, not on screenprojected points. So unproject the map boundary corners (they may actually be already available as map.bounds?) to latlongs (so only has to be done once per frame). Figure out the marker delta latlongs to account for width/height for the marker, and calculate (if all the markers are the same, as an optional param that width/height latlong delta could be cached). Then you don't need to do any marker projections at all ? Not entirely sure if I'm making sense and there's no flaws :D. |
hmm maybe there's an issue with the calculation of the marker widths and height not taking into account the curvature or something, so maybe a good reason it's not done like that, but maybe it could be a useful custom pre-culling of points by someone when creating their marker lists. |
It's not an answer to your question directly but an alternative solution is to use marker clustering (see the clustering plugin listed in the README). I have less markers (~1300) but it is very fast. |
The problem is that, even with markers clustering, map lags even when there are no markers visible at all I currently fixed it in my fork and I'm temporary using it unitl it gets merged |
Indeed, clustering doesn't make any difference to perf. @TheLastGimbus maybe providing a 60fps comparison gif might help gaining some attention From my experience, original leaflet js deals with thousands of markers very well in the browser, though |
SEE? THIS IS HOW BAD THIS IS!!! MERGE THIS TO STOP THIS CIRCUS 🤡 I love this 😍 😆 will add soon
This keeps scratching my head. How do some web devs have their maps filled with markers, running 60fps in browser on my shitty phone, meanwhile "super native optimized Flutter cool framework" can't do >100 displayed at once 😖 Maybe doing some "direct Canvas painting magic" would help, but I have 0 motivation to try this now - maybe some day as extra plugin for this |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
This issue was closed because it has been stalled for 5 days with no activity. |
Hi there!
I am currently making an app which will have a lot of markers - around 4000 spread across whole country. After some testing, it got obvious that all of this gets super laggy
When I use all 3.5k markers and zoom on area with no markers at all, and start dragging the map, I get ~12 fps, on phisical Android tablet in
profile
modeAfter some debugging,
print()
ing andStopwatch()
ing, I traced which parts use the most time:In
lib/src/layer/marker_layer.dart
->MarkerLayer
->build()
, there is afor-loop
that iterates over all givenMarkerks
:flutter_map/lib/src/layer/marker_layer.dart
Line 130 in f09b193
The whole thing was taking ~25ms, and with
Stopwatch()
, I traced which parts of loop use the most time:This was taking around 7500 us:
flutter_map/lib/src/layer/marker_layer.dart
Line 131 in f09b193
This 3600:
flutter_map/lib/src/layer/marker_layer.dart
Lines 132 to 133 in f09b193
And the rest around 0:
flutter_map/lib/src/layer/marker_layer.dart
Lines 140 to 152 in f09b193
So I started to dig into
.project()
:flutter_map/lib/src/map/map.dart
Lines 417 to 420 in f09b193
flutter_map/lib/src/geo/crs/crs.dart
Lines 26 to 34 in f09b193
this.scale()
andtransformation.transform()
don't seem to be expensive - they are only some basic calculations...So,
projection.project
:flutter_map/lib/src/geo/crs/crs.dart
Lines 450 to 456 in f09b193
https://github.com/maRci002/proj4dart/blob/7eb11da840ce21c78c017e0a89ee0332ba5a60e3/lib/src/classes/projection.dart#L152
Okay... this ^ is big, and not even a part of this repo, so I don't think we can do anything about it...
Conclusions
While re-building
MarkerLayer
(which happens constantly while dragging the map), we are doing some expensive calculations, which slow down the whole map - that is, calculating someposition
fromLatLng
// I didn't dig into
pos.multiply
(step which was taking 3600us), and I don't really know what it's doing...I'm fresh into this project and I don't know much about mapping, but it seems like we could somehow cache just the
projection
, and apply onlyscale
andtransformations
- since only them really change when you drag the map(This generally seems related #768, but discussion there got kinda chaotic, not knowing what issue actually was, so I'm making this separate)
The text was updated successfully, but these errors were encountered: