-
Notifications
You must be signed in to change notification settings - Fork 6k
[iOS] Flush layer pool after platform view dispose #54056
Conversation
`FlutterPlatformViewLayerPool` is a pool of iOS layers used for rendering platform views on iOS. When layers are no longer needed, we currently mark them available for re-use but we never actually flush them and thus recover the memory associated with these layers once we know that the platformview is no longer used. We now flush the layer pool to recover unused memory after platform views have been disposed. See: flutter/flutter#152053
|
Taking a look at how to sneak a test in here. |
jonahwilliams
left a comment
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.
Changes look reasonable to me, modulo a test.
|
LGTM |
|
Added a test. |
jonahwilliams
left a comment
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
| auto pool = flutter::FlutterPlatformViewLayerPool{}; | ||
|
|
||
| // Add layers to the pool. | ||
| auto layer1 = pool.GetLayer(gr_context.get(), ios_context, MTLPixelFormatBGRA8Unorm); |
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.
Is there a way to check this is actually released? Or is that not a concern? I know the __weak/@autoreleasepool pattern won't work with non-Obj-C objects.
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.
The pool holds these in std::shared_ptr<FlutterPlatformViewLayer> so they'll be cleaned up via RAII. If we templatized FlutterPlatformViewLayerPool we could stick in some other class and manipulate a count in the ctor/dtor that we could then test against, but that probably wouldn't give us much more benefit, since it still wouldn't show that the real FlutterPlatformView layer properly releases its memory -- it uses C++ smart pointers for all but the GrDirectContext so I trust it, but it's still not tested.
An integration test that looks at overall memory is probably the way to do something like that.
Since this method isn't mutating the pool, we should mark it const. Cleanup spotted while working on #54056. No test because no semantic change. The compiler is the test. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
…152203) flutter/engine@f5ec4ab...1572635 2024-07-24 [email protected] Change JSArray.length to return int (flutter/engine#54051) 2024-07-24 [email protected] Roll Dart SDK from 17131486a2f7 to e53beb039093 (1 revision) (flutter/engine#54066) 2024-07-24 [email protected] Roll Fuchsia Linux SDK from ZcBsXDojTYbriHD7_... to qA7S-DZ5FyMtcM7_J... (flutter/engine#54064) 2024-07-24 [email protected] [DisplayList] Fix assertions on DisplayList verbose comparison tests (flutter/engine#54065) 2024-07-24 [email protected] Roll Fuchsia Test Scripts from 5bzzKaW7fCp_No_w_... to clqtZA8cx4GEXwcOe... (flutter/engine#54063) 2024-07-23 [email protected] [iOS] Flush layer pool after platform view dispose (flutter/engine#54056) 2024-07-23 [email protected] [iOS] Mark EmbeddedViewCount const (flutter/engine#54062) 2024-07-23 [email protected] Roll Skia from f4355cf73508 to 3f1b4e98f65a (1 revision) (flutter/engine#54060) 2024-07-23 [email protected] Roll Skia from 2d518b6a793a to f4355cf73508 (9 revisions) (flutter/engine#54058) 2024-07-23 [email protected] Roll Dart SDK from eeb2e4e409bf to 17131486a2f7 (1 revision) (flutter/engine#54055) 2024-07-23 [email protected] Roll Skia from a9019fddac28 to 2d518b6a793a (4 revisions) (flutter/engine#54052) 2024-07-23 [email protected] [Impeller] add emulated advanced blend support for exp canvas. (flutter/engine#54020) 2024-07-23 [email protected] Roll Skia from 1cda2a7b0ee4 to a9019fddac28 (3 revisions) (flutter/engine#54050) 2024-07-23 [email protected] [DisplayList] track unbounded state on save layers and DisplayLists (flutter/engine#54032) 2024-07-23 [email protected] Temporarily disable use of glBlitFramebuffer on NVIDIA (flutter/engine#54040) 2024-07-23 [email protected] Set the view ID for FlView (flutter/engine#54043) 2024-07-23 [email protected] [Impeller] Implement OpenGL to Vulkan texture trampolining. (flutter/engine#53966) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from ZcBsXDojTYbr to qA7S-DZ5FyMt If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] 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
|
This led to a nice memory drop on a varierty of benchmarks: |
|
With a slight increase in some worst fame times (probably from re-creating the overlays): |
|
That seems reasonable. We could potentially tweak the pool clearing code to do some kind of back-off, but I worry that going down that path might lead to optimising a bit too much for a particular scenario. |
…lutter#152203) flutter/engine@f5ec4ab...1572635 2024-07-24 [email protected] Change JSArray.length to return int (flutter/engine#54051) 2024-07-24 [email protected] Roll Dart SDK from 17131486a2f7 to e53beb039093 (1 revision) (flutter/engine#54066) 2024-07-24 [email protected] Roll Fuchsia Linux SDK from ZcBsXDojTYbriHD7_... to qA7S-DZ5FyMtcM7_J... (flutter/engine#54064) 2024-07-24 [email protected] [DisplayList] Fix assertions on DisplayList verbose comparison tests (flutter/engine#54065) 2024-07-24 [email protected] Roll Fuchsia Test Scripts from 5bzzKaW7fCp_No_w_... to clqtZA8cx4GEXwcOe... (flutter/engine#54063) 2024-07-23 [email protected] [iOS] Flush layer pool after platform view dispose (flutter/engine#54056) 2024-07-23 [email protected] [iOS] Mark EmbeddedViewCount const (flutter/engine#54062) 2024-07-23 [email protected] Roll Skia from f4355cf73508 to 3f1b4e98f65a (1 revision) (flutter/engine#54060) 2024-07-23 [email protected] Roll Skia from 2d518b6a793a to f4355cf73508 (9 revisions) (flutter/engine#54058) 2024-07-23 [email protected] Roll Dart SDK from eeb2e4e409bf to 17131486a2f7 (1 revision) (flutter/engine#54055) 2024-07-23 [email protected] Roll Skia from a9019fddac28 to 2d518b6a793a (4 revisions) (flutter/engine#54052) 2024-07-23 [email protected] [Impeller] add emulated advanced blend support for exp canvas. (flutter/engine#54020) 2024-07-23 [email protected] Roll Skia from 1cda2a7b0ee4 to a9019fddac28 (3 revisions) (flutter/engine#54050) 2024-07-23 [email protected] [DisplayList] track unbounded state on save layers and DisplayLists (flutter/engine#54032) 2024-07-23 [email protected] Temporarily disable use of glBlitFramebuffer on NVIDIA (flutter/engine#54040) 2024-07-23 [email protected] Set the view ID for FlView (flutter/engine#54043) 2024-07-23 [email protected] [Impeller] Implement OpenGL to Vulkan texture trampolining. (flutter/engine#53966) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from ZcBsXDojTYbr to qA7S-DZ5FyMt If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] 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
…lutter#152203) flutter/engine@f5ec4ab...1572635 2024-07-24 [email protected] Change JSArray.length to return int (flutter/engine#54051) 2024-07-24 [email protected] Roll Dart SDK from 17131486a2f7 to e53beb039093 (1 revision) (flutter/engine#54066) 2024-07-24 [email protected] Roll Fuchsia Linux SDK from ZcBsXDojTYbriHD7_... to qA7S-DZ5FyMtcM7_J... (flutter/engine#54064) 2024-07-24 [email protected] [DisplayList] Fix assertions on DisplayList verbose comparison tests (flutter/engine#54065) 2024-07-24 [email protected] Roll Fuchsia Test Scripts from 5bzzKaW7fCp_No_w_... to clqtZA8cx4GEXwcOe... (flutter/engine#54063) 2024-07-23 [email protected] [iOS] Flush layer pool after platform view dispose (flutter/engine#54056) 2024-07-23 [email protected] [iOS] Mark EmbeddedViewCount const (flutter/engine#54062) 2024-07-23 [email protected] Roll Skia from f4355cf73508 to 3f1b4e98f65a (1 revision) (flutter/engine#54060) 2024-07-23 [email protected] Roll Skia from 2d518b6a793a to f4355cf73508 (9 revisions) (flutter/engine#54058) 2024-07-23 [email protected] Roll Dart SDK from eeb2e4e409bf to 17131486a2f7 (1 revision) (flutter/engine#54055) 2024-07-23 [email protected] Roll Skia from a9019fddac28 to 2d518b6a793a (4 revisions) (flutter/engine#54052) 2024-07-23 [email protected] [Impeller] add emulated advanced blend support for exp canvas. (flutter/engine#54020) 2024-07-23 [email protected] Roll Skia from 1cda2a7b0ee4 to a9019fddac28 (3 revisions) (flutter/engine#54050) 2024-07-23 [email protected] [DisplayList] track unbounded state on save layers and DisplayLists (flutter/engine#54032) 2024-07-23 [email protected] Temporarily disable use of glBlitFramebuffer on NVIDIA (flutter/engine#54040) 2024-07-23 [email protected] Set the view ID for FlView (flutter/engine#54043) 2024-07-23 [email protected] [Impeller] Implement OpenGL to Vulkan texture trampolining. (flutter/engine#53966) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from ZcBsXDojTYbr to qA7S-DZ5FyMt If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] 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
FlutterPlatformViewLayerPoolis a pool of iOS layers used for rendering platform views on iOS. When layers are no longer needed, we currently mark them available for re-use but we never actually flush them and thus recover the memory associated with these layers once we know that the layers are no longer needed.We now flush the layer pool on
SubmitFrame. If a previously-used layer is no longer used in the current frame, it is removed. In theory, this could cause a performance regression in the case where an additional layer is needed every second or third frame, but we should keep it simple on the first pass and only complicate things later if warranted.Fixes: flutter/flutter#152053
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.