Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Remove tech debt related to image disposal and layer GC #26870

Merged
merged 4 commits into from
Jun 25, 2021

Conversation

dnfield
Copy link
Contributor

@dnfield dnfield commented Jun 21, 2021

WIP - do not land until after flutter/flutter#84740

  • don't forget to add some test(s) to cover images getting cleaned up when picture/enginelayer is disposed.

Fixes flutter/flutter#84116

ImageReleasedAfterFrame
#endif // defined(OS_FUCHSIA)
) {
TEST_F(ImageDisposeTest, ImageReleasedAfterFrameAndDisposePictureAndLayer) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reviewers take note: this re-enables a test that was flaking on Fuchsia.

However, this test no longer relies on GC behavior and should be fully deterministic now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It also no longer relies on decoding a massive image, and is much faster now too.

Copy link
Member

Choose a reason for hiding this comment

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

flutter/flutter#84116 can be closed when this lands.

@dnfield
Copy link
Contributor Author

dnfield commented Jun 22, 2021

This is ready for review, but I'm going to leave it as a draft until the framework PR that implements this behavior is merged.

Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

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

Dart may wish to deprecate the Dart_HintFreed() API as well after this lands. /cc @rmacnak-google

// Provide an approximation of the total memory impact of this object to the
// Dart GC. The ContainerLayer may hold references to a tree of other layers,
// which in turn may contain Skia objects.
return 3000;
Copy link
Member

Choose a reason for hiding this comment

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

Is the shallow size of the C++ object still tracked as an external allocation for Dart GC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ImageReleasedAfterFrame
#endif // defined(OS_FUCHSIA)
) {
TEST_F(ImageDisposeTest, ImageReleasedAfterFrameAndDisposePictureAndLayer) {
Copy link
Member

Choose a reason for hiding this comment

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

flutter/flutter#84116 can be closed when this lands.

@dnfield dnfield marked this pull request as ready for review June 25, 2021 19:02
@dnfield
Copy link
Contributor Author

dnfield commented Jun 25, 2021

The change in the framework landed. This is ready for review.

Copy link
Member

@bdero bdero left a comment

Choose a reason for hiding this comment

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

lgtm! It's nice to see this go away. Hopefully my understanding is correct here with respect to the picture lifecycle work.

std::shared_ptr<DartIsolate> root_isolate = root_isolate_.lock();
if (!root_isolate) {
return false;
}

tonic::DartState::Scope scope(root_isolate);

// Dart will use the freed hint at the next idle notification. Make sure to
// Update it with our latest value before calling NotifyIdle.
Dart_HintFreed(freed_hint);
Copy link
Member

@bdero bdero Jun 25, 2021

Choose a reason for hiding this comment

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

Could you let me know if my understanding is correct here?

Not tracking/providing this hint for freed images won't cause the GC policy to behave poorly for us because:

  1. Dart references to expensive resources like images is now more tightly managed WRT inclusion in draw lists, and disposal of them is explicit on the framework side, and so...
  2. These expensive resources are now freed outside the confines of GC runs, removing our need to force the Dart GC gate to consider the size of freed images as they pile up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. Running the GC for this is expensive and no longer needed

@dnfield dnfield merged commit b690423 into flutter:master Jun 25, 2021
@dnfield dnfield deleted the img_dispose branch June 25, 2021 22:33
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 25, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 26, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 26, 2021
moffatman pushed a commit to moffatman/engine that referenced this pull request Aug 5, 2021
naudzghebre pushed a commit to naudzghebre/engine that referenced this pull request Sep 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImageDisposeTest.ImageReleasedAfterFrame flaking on Linux Fuchsia FEMU
3 participants