Skip to content
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

EngineLayer::dispose #26219

Merged
merged 16 commits into from
Jun 2, 2021
Merged

EngineLayer::dispose #26219

merged 16 commits into from
Jun 2, 2021

Conversation

dnfield
Copy link
Contributor

@dnfield dnfield commented May 18, 2021

Part of flutter/flutter#81514

In effect, we end up with three layer trees:

  • The Flutter framework (dart) Layer tree, which is how the framework abstracts SceneBuilder. Those layers may or may not hold refernces to EngineLayers. Some framework layers have no corresponding engine layer even though they have a corresponding flow layer (e.g. PictureLayer). Some have no corresponding engine or flow layer.
  • The raster/flow layer tree, which is created on the native side via SceneBuilder and referred to by EngineLayer objects. It may or may not create additional layers that the framework doesn't know about. These layers contain pointers to other layers (child layers), and may also contain pointers to Skia objects (SkShader/SkPicture in particular).
  • The EngineLayer tree, which links between framework and flow layers. It has no notions of parent/sibling/child relationships, and exists solely to help the framework with retained rendering.

The main problem is that the linkage between the framework layers means that flow layers cannot be fully cleaned up until a GC is run. This in turn means that some Skia objects which are no longer necessary get stuck until a GC.

Once this patch has landed and the framework consumes the dispose API correctly, we won't need to trigger GCs on image disposal anymore. We will also much more efficiently clean up Skia and flow Layer* related memory before waiting for a GC, even with the engine holding on to the last_layer_tree at times.

This still needs tests. Marking as draft to start running more tests than I've done locally.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.
  • The reviewer has submitted any presubmit flakes in this PR using the engine presubmit flakes form before re-triggering the failure.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@dnfield dnfield force-pushed the dispose_layers branch 2 times, most recently from 720537d to a4fdb7c Compare May 18, 2021 20:24
@dnfield dnfield marked this pull request as ready for review May 18, 2021 20:33
@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label May 18, 2021
@dnfield
Copy link
Contributor Author

dnfield commented May 18, 2021

@goderbauer FYI since I'll be asking you to review framework side changes related to this.

Copy link
Member

@jason-simmons jason-simmons left a comment

Choose a reason for hiding this comment

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

LGTM


@override
void dispose() {
assert(!_debugDisposed);
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to set _nativeLayer to null after disposing instead of maintaining the _debugDisposed flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess we could make it nullable and avoid the flag. I can change that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - I was worried this would add a ton of null checks, but we basically treat it as nullable in most places anyway.

@goderbauer
Copy link
Member

@dnfield Is there a better view of how this will be integrated into the framework? The diff posted in the issue (https://github.com/flutter/flutter/compare/master..dnfield:disp_pict) seems to contain a lot of unrelated stuff...

@dnfield
Copy link
Contributor Author

dnfield commented May 18, 2021

@goderbauer - everything in that diff is related, even if it seems like it's not :. I'll be splitting that up into the render object portion and the layer portion soon though.

@dnfield
Copy link
Contributor Author

dnfield commented May 18, 2021

@goderbauer
Copy link
Member

Ahhh try https://github.com/flutter/flutter/compare/dnfield:disp_pict

That looks better. Added to my queue.

@zanderso zanderso removed the platform-web Code specifically for the web engine label May 19, 2021
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.

This lgtm. @yjbanov and @chinmaygarde should review as well.

@dnfield
Copy link
Contributor Author

dnfield commented May 19, 2021

One thing I want to think about some more is what to do with oldLayer on the SceneBuilder API. It seems like we should be disposing it after we use it, and documenting that the caller must not use it again after that. Or, we should be documenting that the caller has to dispose it, which seems strange.

@dnfield dnfield added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jun 1, 2021
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Linux Host Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac Host Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jun 1, 2021
@dnfield dnfield added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jun 2, 2021
@fluttergithubbot fluttergithubbot merged commit 2f705e8 into flutter:master Jun 2, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 2, 2021
naudzghebre pushed a commit to naudzghebre/engine that referenced this pull request Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
5 participants