flutter / devtools

Performance tools for Flutter
https://flutter.dev/docs/development/tools/devtools/
BSD 3-Clause "New" or "Revised" License
1.59k stars 326 forks source link

Improve performance for code size screen #2173

Closed peterdjlee closed 4 years ago

peterdjlee commented 4 years ago
peterdjlee commented 4 years ago

Is there a way to keep tabs truly persistent?

I've tried looking at this article which states that using AutomaticKeepAliveClientMixin should help. I was able to stop the tabs from rebuilding, but that didn't seem to noticeably improve the performance. Either rebuilding isn't the problem or my method of checking if the widget is rebuilding is wrong.

peterdjlee commented 4 years ago

I've tried looking at this article which states that using AutomaticKeepAliveClientMixin should help. I was able to stop the tabs from rebuilding, but that didn't seem to improve the performance. Either rebuilding isn't the problem or my method of checking if the widget is rebuilding is wrong.

Rebuilding widgets: ezgif com-video-to-gif (3)

Not rebuilding widgets: ezgif com-video-to-gif (4)

kenzieschmoll commented 4 years ago

Is each tree map cell wrapped in a Tooltip?

peterdjlee commented 4 years ago

Is each tree map cell wrapped in a Tooltip?

Yup. All cells and also the title bars are wrapped in a Tooltip.

peterdjlee commented 4 years ago

Yup. All cells and also the title bars are wrapped in a Tooltip.

Can confirm that removing all Tooltip widgets and Inkwell widget shaves off about a second each, reducing around 66% of the loading time. So one optimization we can do would be to limit the number of widgets we wrap with Tooltip and Inkwell.

kenzieschmoll commented 4 years ago

It is very expensive to initialize all those listeners. We had to do something creative in the flame chart where we wrapped the whole chart in a MouseRegion widget and tracked the (x, y) hover position. Then based on that position, we did an efficient search for the element that would be at that position, rebuilding the widget that should then be wrapped in a tooltip. Something like this may be tricky for the treemap, as I don't know that we'd be able to use binary search like we were able to in the flame chart. For this to be useful, we'd have to have an efficient way to find a treemap element based on an (x, y) position.

peterdjlee commented 4 years ago

I've tried looking at this article which states that using AutomaticKeepAliveClientMixin should help. I was able to stop the tabs from rebuilding, but that didn't seem to noticeably improve the performance. Either rebuilding isn't the problem or my method of checking if the widget is rebuilding is wrong.

Update: The tabs were not rebuilding but each treemap cell was still rebuilding. I tried building Treemap widgets AutomaticKeepAliveClientMixin but for some reason that did not prevent the Treemap widgets from rebuilding.

peterdjlee commented 4 years ago

Would it be okay to only wrap the 1st level items in Inkwell and Tooltip? Essentially, clicking on a cell won't make the node of that cell the root of the treemap. If removing the ability to jump to a cell on click isn't a big inconvenience to the users, I think it'd be a good optimization. I'm not really sure what the users would want though.

kenzieschmoll commented 4 years ago

The Treemap navigation is really the only way a user can dig through the data, so we don't want to remove the ability for the user to change the root and "zoom" into the tree.

peterdjlee commented 4 years ago

Sorry, I meant that the user will still be able to zoom in but only a level deeper. For example in the screenshot below, clicking on 'src' under package:flutter will reroot the treemap to the package:flutter node instead of src node. So if a user tried clicking on any of the small cells under 'dart:typed_data', the treemap would reroot with the dart:typed_data node, not the actual cell the user clicked on.

Screen Shot 2020-07-14 at 1 08 59 PM
kenzieschmoll commented 4 years ago

hmm.. that feels like it may be confusing to a user that what they click doesn't actually become the root. If you remove just the tooltips and leave the inkwells, does that improve the perf?

peterdjlee commented 4 years ago

I agree. Maybe adding some sort of color filter to indicate on hover that the selection applies to the entire rectangle would help with that. Yep, removing both seems to reduce the loading duration down to at least 50%.