-
-
Notifications
You must be signed in to change notification settings - Fork 871
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
refactor: use separate painters for each Polyline
#1697
refactor: use separate painters for each Polyline
#1697
Conversation
Change PolylineLayer logic to have a custom painter for each polyline, this allow the layer to not overtake the map tap on objects that are not part of the polylines
Hello, |
Thanks @thomascoumau! I'm wondering how having multiple custom painters will impact performance. Previously, It's also important to note that this breaking (albeit only for a minority of users), and so may not appear in a release for a little while - we don't want to overwhelm users with too many breaking changes. This isn't too important though. |
Hey, sorry for the late response. |
I can't really explain it myself, but I guess it's similar to the reason |
Yeah, I think we need some testing on the performance of course. Do you want me to make some tests and send you a report of them. I never really have tested the performance on my app but I am eager to learn and I think this would be a good opportunity. If you have any tests I must do let me know, or if you don't want me to run the investigation let me know to 👌 |
I don't mind you running the tests. Just need to not change anything else except this, then compare FPS based on number and length of polylines. |
Performance aside (Jaffa is right, drawing one path with many lines to a canvas is cheaper than drawing many lines to the same canvas. Each draw call just makes the CPU tell the GPU to draw eagerly), is the goal to make individual polylines tappable? Even with many small Canvases stacked on top, I'd expect this to be challenging. At the of the day, the canvas is rectangular and not line shaped. If it works for your use-case, I may suggest to just Stack many PolylineLayers rather than changing the PolylineLayer itself. The Result should be the same. |
Hello @ignatz, |
Ok thank you for your response I understand a little better your position on why it should be only one canvas for all the polylines. However, I tested and using different canvas dont impact the detection since I override the path taken in the hitTestBehavior to match the drawing on screen. I think I should run the performance test before trying to change all the implementation on this matter. PS: Sorry for the really late response |
Hi @thomascoumau, after you mentioned it I saw that you overwrote the hit test behavior in another branch, that makes sense. Couldn't use a similar approach for when there's more than one line on a canvas? FWIW, I do something similar in my app for polygons. I'd love to have tapable polylines. |
Hi @ignatz, it is possible to override the hitTest for all the polyline at once in one canvas. As I explained before, I want to test first if having a canvas per polyline is impacting the performance otherwise I think it is better to keep having a painter per polylines. |
In principle yes, you just have to do a bit more work to narrow down the corresponding lines. What I do for polygons is to first prune all the polygons that don't have an overlapping bounding box and then use a more complex algorithm to find whether the tap is inside the polygon. With the multiple canvases you basically get the bounding boxing and z-axis ordering for free.
You can estimate the impact at HEAD w/o any code changes. Draw your polylines once with a transparent color and once with an opaque color (the latter needs to be the same color for all lines). The transparent color will result in individual draw calls, alas into the same canvas but the performance should be similar. Whereas the opaque lines will all be drawn in one go. You should experience a significant performance difference. |
I ended up looking into this, since I also could use some tappable polylines. This is what I ended up with: https://github.com/ignatz/flutter_map-clone/blob/polyline_tap/lib/src/layer/polyline_layer.dart |
Polyline
Polyline
Polyline
Huge thanks for contributing, but after discussion, this has been replaced by #1728. We're still up for curved lines in future though! |
Polyline
Polyline
Change PolylineLayer logic to have a custom painter for each polyline, this allow the layer to not overtake the map tap on objects that are not part of the polylines