flutter / devtools

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

Debug memory usage associated with the widget tree #2513

Open jacob314 opened 3 years ago

jacob314 commented 3 years ago

The only way to currently debug memory usage from the widget tree is to manually disable portions of the tree by editing code and then compare the overall memory usage. That mechanism while highly manual has proven effective in identifying cases where specific widgets are greatly increasing graphics memory usage.

Possible solutions:

  1. Use the existing VM snapshots perhaps combined with a kernel transformer tracking ids for the creator objects to accurately attribute Dart memory allocated due to specific widget trees. This solution should work well for memory within the Dart heap but will be unable to correctly attribute graphics memory for widgets.

  2. Simulate widget trees with each possible widget subtree removed to provide the exact memory usage impact of each widget. This would be slow (for example requiring 1000s widget tree rebuilds to generate the stats) but would provide accurate #s about the real world memory usage of each widget as graphics memory could be correctly accounted for without requiring changes to SKIA. 10,000 rebuilds at 100ms per rebuilds is 17 minutes so the tool would be slow but usable. Simulations could be performed on a debug build reusing hot reload or on a profile build using a kernel transformer.

Action items:

  1. Determine whether debug mode VM memory usage for widgets is sufficiently correlated with profile mode memory usage by widgets to allow widget memory debugging tools to depend on debug only features.
  2. Determine whether Dart VM memory usage by widgets is sufficiently correlated with graphics memory used by widgets for it to be sufficient for users to only optimize Dart VM memory usage by widgets.

@terrylucas @mehmetf

bkonyi commented 3 years ago

@jacob314 is there any support you'd need from the VM service for this? If so, please let me know!