-
Notifications
You must be signed in to change notification settings - Fork 6k
Add a custom switch to clean up the leaked Dart VM #30541
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
b87799d
to
6c888c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @blasten for whether this we should do this. I think, if anything, we should switch the default on the flag to never leak the VM.
Ideally, this flag should not exist and the last instance of the shell should always collect the VM. But this was added because of benchmark regressions on application resumption. IMO, we should migrate to non-leaky behavior instead of exposing another flag.
6c888c9
to
5b453a2
Compare
shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java
Outdated
Show resolved
Hide resolved
@goderbauer @dnfield Some context about this flag: Lines 198 to 209 in ea734ba
|
This change seems reasonable. I also think that the default behavior should be to never leak the VM. Do you know how this interacts with cached engines, e.g. https://api.flutter.dev/javadoc/io/flutter/embedding/engine/FlutterEngineCache.html ? |
This flag was specifically set up because on Android and iOS applications, going to and from background was causing the VM to restart. We don't want that to happen because it is slow to restart the VM. |
I agree with you. And also add the |
…terLoader.java Co-authored-by: Emmanuel Garcia <egarciad@google.com>
73735eb
to
47c8982
Compare
47c8982
to
5303a59
Compare
Let's land this change with the current default. Please file an issue to change the default value, and add TODO with the link to the issue. Another PR can change the default to |
shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java
Outdated
Show resolved
Hide resolved
Also add example code in add-to-app sample project
shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Added a sample code in: |
It's both Android and iOS part of:
Considering the
leak_vm
setting is a process global option, I put it into AndroidManifest.xml's app meta-data, like theOldGenHeapSize
option.Demo app link: https://github.com/eggfly/flutter_leak_vm_test
Code:
https://github.com/eggfly/flutter_leak_vm_test/blob/612b2271c90de68f9bbaf03696fcdb18bcd73745/android/app/src/main/AndroidManifest.xml#L51
Keep switching between native MainActivity and flutter activity, and observe the memory usage.
LeakVM is true (or not set): back to native Activity then native memory = 34.9MB

LeakVM is false: back to native Activity then native memory = 32.2MB

Some debug logs:
Pre-launch Checklist
writing and running engine tests.
///
).