-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Poor performance when subscribing to MouseRegion events #41194
Comments
cc @ditman |
Woah, I'll try to profile this to see where the time is going, since I recently tweaked some rendering of DRRects. Thanks for the repro code! |
The current implementation generates a new frame for every mouse move, but that would only produce a regression when the mouse is moving, not otherwise. There's a fix for that in #41014 |
@gspencergoog, today we just switched our Flutter installation to this commit in #41014 and the issue is still there, we didn't notice any improvements in our cases... |
OK, that's as I suspected. More likely it has to do with the rendering. |
I did some profiling, and the issue seems to be related to a spike on DOM operations, and not necessarily to how we draw drrects into canvas (phew). I'll keep digging. @LehaIvanov you call this a 'regression': has this ever worked well for you, and then it started being slow after some change, or is it just that performance gets worse when adding the onEnters? |
@ditman thank you for your help with this issue. I used "regression" term by mistake: this is not a regression - I had never seen this working well. We also did some investigations and we almost pretty sure that this issue not related to rounded rect painting: it seems to be related to engine/compositing code and/or DOM operations. Please let me know if you need any further help with this. We plan to go to production with Flutter Web in a few months and this is currently the only blocker we have. So I will definitely do everything |
@LehaIvanov So after a bunch of investigation, it seems that the issue is that active MouseRegions create additional PictureLayers that "break" the optimizations that the relayout boundaries of the Row widget provide (we end up with "too many layers", which in web translates to "too much DOM churn"). I have a pushed a fix to my flutter fork (which you can maybe try on your app?), but I need to seek approval from the owners of the MouseRegions feature (@gspencergoog ?), because I might be breaking something that I'm not even aware of. Apologies for the delayed response, it took me a while to figure a root cause for this one :) |
The MouseRegion creates AnnotatedRegion layers in the layer tree, which I assume are passed to the web engine as is? These don't have any effect on rendering, so it might be possible to filter these out, so to speak, when talking to the web engine |
@ditman, thank you very much for your efforts working on this issue. Today we tested your fork with our cases and everything works great! Actually, we are trying to render many elements on screen with tooltips. We found another performance issue (not related to this one) with tooltips / global routes. We plan to fill an issue and create a PR that fixes it ourselves in a few days. So we are looking forward to see your changes in Flutter master soon :) |
@LehaIvanov thanks, we're looking forward to see what you put in production, if it's publicly available! @jonahwilliams I think that's more or less what I did. The "problem" seems to be that instead of having a tree like this:
(Which is the case when the MouseRegion is not active) we end up with this:
So the relayout boundary of the Row, which allows it to bunch a group of paints together into a larger PaintLayer is split into smaller ones (children of the MouseRegion), which in turn causes a very large number of DOM nodes to be created and moved around. This is not a big problem in other platforms, where canvas allocation is not as bad (in fact the OP says that with the Skia backend, this is fine), but in normal web with canvas, touching the DOM this much is quite expensive and performance drops. I didn't find a (fast) way to do post-processing here, since layer creation is somewhat tied to DOM nodes. We may be able to brainstorm some ideas for a more proper fix for this, rather than "don't break up the rendering when pushing layers that really don't paint anything", but that felt like a much larger scope (to the point that I'm not entirely sure how large it'd be :P) |
I'd like explore the possibility of removing the need of annotated region layers and letting the parent layer or the layer tree take care of the annotation. However I'll have to do it after my current project (mouse cursor). |
Thanks for taking this over @dkwingsmt! I'm going to dis-assign myself, since I'm not going to work on this directly. Feel free to ping me if I can be of any assistance (I'll keep my branch up just for reference, at least for a while)! |
Hi, is there any update for this issue? |
@hossainiir I do have a plan for this and I’m working on it now. It is due to some design issues about hover detection and we want to fix it in the most elegant way. |
@dkwingsmt Thanks, In my app I have about 100 controls that have MouseRegion, this issue causes my app to have lot lags. |
I also created a little pet project web application, deployed it and the performance is extremely slow... I mean I am unable to scroll the site on mobile. I hope it gets fixed because I have great plans for flutter web :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Hello,
Currently we developing a Flutter Web application with the intent to move to production in a few months. Almost everything works great but we found a major performance issue when subscribing to mouse events for many widgets.
We use
ListView
to display/scroll grid-like data and scrolling performance is 60fps on our testing devices which is perfect for us. But when we attach mouse event listeners to our widgets/cells we get major performance regression. (we tried to show tooltips usingTooltip
widget but the problem seems to be much wider).We found that this issue somewhat relates to widgets having rounded borders and/or different borders specified for each side. The problem should be easily reproducible so we provide only minimal
main.dart
examples without videos.Scrolling in both examples below produces less than 60fps, but if you comment
onEnter: (_) => {}
handler inMouseRegion
performance will increase dramatically and will reach 60fps.main.dart: Case 1: Border radius
main.dart: Case 1: Different side borders
We also found that the issue does not appear if we enable
Skia
based renderer so its source might be inFlutter Web
engine, not in framework.Please let me know if you need any additional information (videos, profile snapshot, etc) to diagnose the issue.
We wonder if there any existing issues/plans to improve Flutter Web performance in such scenarios, or is there any workaround for this?...
The text was updated successfully, but these errors were encountered: