-
-
Notifications
You must be signed in to change notification settings - Fork 888
perf: preserve Marker
widget state when list of visible markers changes
#2131
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
base: master
Are you sure you want to change the base?
Conversation
I found out that m.key is null for all markers, So as soon as children of Stack changed they all rebuild. 2025-07-21.14-49-06.mp4So now with non null key and RepaintBoundary we preserve the state. 2025-07-21.14-50-08.mp4 |
Ahh. I missclicked and closed PR. So reopened. 2025-07-21.14-51-36.mp4Unlike before it was lagging as soon as any marker left the screen. 2025-07-21.14-52-57.mp4But need to figure out how to give it a stable and uniqe Key. If you have any ideas, welcome to contribute. |
Prehaps can add UniqueKey but then cannot make Marker const Marker({
Key? key,
required this.point,
required this.child,
this.width = 30,
this.height = 30,
this.alignment,
this.rotate,
}) : key = key ?? UniqueKey(); |
This is a nice fix, thanks. But I would first like to find out when this issue was introduced, since I don't remember it always being there. Is this ready for review? |
Hi. Not yet. Still need to figure out what key to use. Right now, the key is based on the marker’s location, but if two markers share the same location, it throws a “Duplicate keys found” exception. As I mentioned, I’m not sure what the best key would be in that case. One option might be to use a UniqueKey when creating each marker, which would avoid the duplicate issue, but then I wouldn’t be able to declare the Marker as const. That could reduce some of the performance optimizations Flutter provides. |
I don't know if it's possible, but that might suggest using keys isn't the best way around this. At the moment, we run a function/generator to return widgets. I guess So maybe we need to go a little more complex than For example, see #2134.
|
Ah yes ObjectKey can be used. #2134 looks good, Not sure I understand it all. I don't have much experiance with custom RenderObjects. |
@ReinisSprogis For the moment, #2134 is nice but low priority for me right now (I've got limited time for the next while). I think that's the "correct" way to do things - moreso the "right" way to support multi-worlds (as it just renders multiple times instead of building multiple times) - but it's a lot to figure out and I'm struggling with the rotation stuff & coordinate maths (as I mentioned there). It's close to working, but not there just yet. + research is needed into culling need. Therefore, for the time being, this might be worth perusing if you're still interested. Renaming stuff is not possible for the time being. If a user wants to overlay a widget more precisely, there's a plugin for that which we could consider incorporating in the future, but the marker API & usage is pretty standardised across mapping libraries and so doesn't need changing. But if using the |
Marker
widget state when list of visible markers changes
Hi @JaffaKetchup. I am bit busy at the moment too. I can check on this some time next week. |
I don't know why, but seems like performance is overal reduced with this fix. But removes that lag when markers are culled. |
Added ValueKey and RepaintBoundary to preserve Marker state. m.key was always null. However, might be that implementation can produce duplicate Keys if coordinates of the two markers are the same. Need a better sollution for key, but this is start.