Skip to content

[camerax] Shorten interval for releasing weak references to Dart-wrapped native objects #6493

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

Merged
merged 11 commits into from
Apr 10, 2024

Conversation

camsim99
Copy link
Contributor

@camsim99 camsim99 commented Apr 9, 2024

This PR:

  1. Shortens the InstanceManager's default time interval that it waits to remove references to Dart-wrapped Android native objects. The shortened interval matches webview_flutter_androids InstanceManager; because it has been tested by that plugin, we expect it not to impact performance and this could help reduce overall memory usage by the plugin.
  2. Dynamically shortens that same time interval whenever image streaming is started/stopped to account for the increased memory usage that this camera use case requires.

Fixes flutter/flutter#145893.

Pre-launch Checklist

@camsim99 camsim99 marked this pull request as ready for review April 9, 2024 19:32
@camsim99 camsim99 requested review from bparrishMines and a team April 9, 2024 19:33
Copy link
Member

@gmackall gmackall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't set to 1000 all the time? The fact that we are switching seems to imply some sort of trade off to me (otherwise we could just stay at 1000 right?) but it isn't clear to me what that trade off is.

Is it just the potential of performance impact? But we are fine with that potential performance impact when we need the shorter interval because image streaming demands it?

// collected weak references to native Android objects that it manages in order to
// account for the increased memory usage that comes from analyzing images with an
// ImageAnalysis.Analyzer.
instanceManager.setClearFinalizedWeakReferencesInterval(1000);
Copy link
Member

@gmackall gmackall Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this also get a descriptively named constant

@camsim99
Copy link
Contributor Author

Is there a reason we can't set to 1000 all the time? The fact that we are switching seems to imply some sort of trade off to me (otherwise we could just stay at 1000 right?) but it isn't clear to me what that trade off is.

Is it just the potential of performance impact? But we are fine with that potential performance impact when we need the shorter interval because image streaming demands it?

Yes, you hit the nail on the head--we just aren't sure that it wouldn't impact performance, but we know that to avoid a crash, we have to lower it for image streaming. We could lower the default below 3000, but it doesn't seem necessary for any other camera use cases so far.

@camsim99 camsim99 requested a review from gmackall April 10, 2024 17:15
@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 10, 2024
@flutter-dashboard
Copy link

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 "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

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.

@auto-submit auto-submit bot merged commit 6f0ed15 into flutter:main Apr 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 11, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Apr 11, 2024
flutter/packages@2c15d86...e98839a

2024-04-10 ekuleshov@gmail.com [tool] Check for `test` and `flutter_test` in non-dev dependencies (flutter/packages#6472)
2024-04-10 43054281+camsim99@users.noreply.github.com [camerax] Shorten interval for releasing weak references to Dart-wrapped native objects (flutter/packages#6493)
2024-04-10 engine-flutter-autoroll@skia.org Roll Flutter from 4967a94 to 97cd47a (11 revisions) (flutter/packages#6497)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
gilnobrega pushed a commit to gilnobrega/flutter that referenced this pull request Apr 22, 2024
flutter/packages@2c15d86...e98839a

2024-04-10 ekuleshov@gmail.com [tool] Check for `test` and `flutter_test` in non-dev dependencies (flutter/packages#6472)
2024-04-10 43054281+camsim99@users.noreply.github.com [camerax] Shorten interval for releasing weak references to Dart-wrapped native objects (flutter/packages#6493)
2024-04-10 engine-flutter-autoroll@skia.org Roll Flutter from 4967a94 to 97cd47a (11 revisions) (flutter/packages#6497)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
TecHaxter pushed a commit to TecHaxter/flutter_packages that referenced this pull request May 22, 2024
…ped native objects (flutter#6493)

This PR:

1. Shortens the `InstanceManager`'s default time interval that it waits to remove references to Dart-wrapped Android native objects. The shortened interval matches `webview_flutter_android`s `InstanceManager`; because it has been tested by that plugin, we expect it not to impact performance and this could help reduce overall memory usage by the plugin.
2. Dynamically shortens that same time interval whenever image streaming is started/stopped to account for the increased memory usage that this camera use case requires.

Fixes flutter/flutter#145893.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: camera platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StartImageStream causes memory leak, frequently crashes [camera_android_camerax]
2 participants