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

[ios_platform_view] only recycle maskView when the view is applying mutators #41573

Merged
merged 3 commits into from May 16, 2023

Conversation

cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented Apr 28, 2023

A mistake was introduced in #39498 where the maskViews are already recycles each frame.

Sometimes a PlatformView does not need to be re-composite: (https://github.com/flutter/engine/blob/main/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm#L398-L401), so the mask view for such PlatformView should not be recycled.

This PR changed the recycleMaskViews API to allow individual maskviews to be recycled. ApplyMutator then only recycle the maskView for that particular PlatformView.

The MaskViewPool is also reworked to be simpler.

  • The pool now contains a single set of mask views, there is no index counter needed.
  • When a maskView is needed, try to get it from the pool.
    • If pool is empty, create a new view.
    • If pool has an available maskview, remove it from the pool.
  • When a PlatformView starts to applyMutator, it removes current the maskView, insert the maskView to the pool.
  • When the above PlatformView needs to a maskView, it grabs one from the pool.

fixes: flutter/flutter#125620

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.

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

@cyanglaz cyanglaz requested a review from jmagman April 28, 2023 05:13
@cyanglaz cyanglaz marked this pull request as ready for review April 28, 2023 05:13
@cyanglaz cyanglaz added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 28, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 28, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Apr 28, 2023

auto label is removed for flutter/engine, pr: 41573, due to - The status or check suite Linux mac_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

@cyanglaz cyanglaz added the autosubmit Merge PR when tree becomes green via auto submit App label May 1, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 1, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented May 1, 2023

auto label is removed for flutter/engine, pr: 41573, due to - The status or check suite Linux mac_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

@cyanglaz
Copy link
Contributor Author

cyanglaz commented May 2, 2023

Still some arm failures: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8782280206955702993/+/u/test:_Scenario_App_Integration_Tests/stdout

Yes, I discovered some other bugs in the maskViewPool, which was caused because I had an assumption that all maskView can be recycled every frame. This isn't true because sometimes, a PlatformView doesn't need to be re-composited, thus the ApplyMutator function is not called for those views.

I'm working on a fix and should have it ready by EOD today.

@cyanglaz
Copy link
Contributor Author

cyanglaz commented May 2, 2023

I've seen some failures locally but shouldn't be related to this PR. (They didn't fell in this PR in previous ci runs).
Filed: flutter/flutter#125913

@cyanglaz cyanglaz requested a review from jmagman May 2, 2023 21:44
[maskView reset];
}
self.availableIndex++;
maskView = [self.pool anyObject];
Copy link
Member

Choose a reason for hiding this comment

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

How do you know if this view is available for reuse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the view is in use, it is removed from the pool:
See line 493 below.

@jmagman jmagman requested a review from hellohuanlin May 2, 2023 21:55
self.availableIndex = 0;
- (void)insertViewToPool:(FlutterClippingMaskView*)maskView {
FML_DCHECK(![self.pool containsObject:maskView]);
[self.pool addObject:maskView];
Copy link
Contributor Author

@cyanglaz cyanglaz May 3, 2023

Choose a reason for hiding this comment

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

The user of the maskView decides to insert the view back to the pool when they are done with the maskView

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: need to add capacity check here.

@cyanglaz cyanglaz changed the title [ios_platform_view] recycle maskView at the beginning of the frame [ios_platform_view] only recycle maskView when the view is applying mutators May 3, 2023
@cyanglaz cyanglaz requested a review from jmagman May 3, 2023 18:41
@cyanglaz
Copy link
Contributor Author

cyanglaz commented May 3, 2023

Updated PR description to reflect the new approach.

@cyanglaz
Copy link
Contributor Author

cyanglaz commented May 9, 2023

Note to self:
Add a comment in CompositeWithParams and ApplyMutator to explain these methods are not called for all the views every frame.
Add a comment to explain the views in the pool are the ones that are not in use.

@chinmaygarde
Copy link
Member

This seems WIP till @cyanglaz is back.

@chinmaygarde chinmaygarde added the Work in progress (WIP) Not ready (yet) for review! label May 11, 2023
@cyanglaz cyanglaz marked this pull request as draft May 11, 2023 21:07
remove format

revert format change

fix typo

draft

rework recycle pool

fix

comments and documents
@cyanglaz cyanglaz marked this pull request as ready for review May 15, 2023 22:29
//
// The `bounding_rect` is the final bounding rect of the PlatformView
// (EmbeddedViewParams::finalBoundingRect). If a clip mutator's rect contains the final bounding
// rect of the PlatformView, the clip mutator is not applied for performance optimization.
//
// This method is only called when thew `embedded_view` needs to be re-composited at the current
Copy link
Contributor

Choose a reason for hiding this comment

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

typo


@end

@implementation FlutterClippingMaskViewPool : NSObject

- (instancetype)initWithCapacity:(NSInteger)capacity {
if (self = [super init]) {
_pool = [[NSMutableArray alloc] initWithCapacity:capacity];
_pool = [[NSMutableSet alloc] init];
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: initWithCapacity to save some hash extending operations?

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 have considered it and decided go against it.
For most of the pages, there are only 1 static PlatformViews. And even for scrolling situation, it is rear that many PlatformViews need to be clipped at the same time. So the set would rarely hit the capacity.

Or maybe change it to initWithCapacity:1during initialization? I think in most cases, the PlatformView would have a clip.

return maskView;
}

- (void)recycleMaskViews {
self.availableIndex = 0;
- (void)insertViewToPool:(FlutterClippingMaskView*)maskView {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: insertViewToPoolIfNeeded?

@@ -1473,7 +1651,8 @@ void addPlatformView(
const int valueString = 7;
const int valueUint8List = 8;
const int valueMap = 13;

print(_createdPlatformViews);
print(platformViewKey);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

//
// Note that `views_to_recomposite_` does not represent all the views in the view hierarchy,
// if a PlatformView does not change its composition parameter from last frame, it is not
// included in the `views_to_recomposite_`.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should put this in implementation file instead, since we rarely look at the header file. A large part of them are more helpful to implementors and not callers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

@cyanglaz cyanglaz added autosubmit Merge PR when tree becomes green via auto submit App and removed Work in progress (WIP) Not ready (yet) for review! labels May 16, 2023
@auto-submit auto-submit bot merged commit 17d5100 into flutter:main May 16, 2023
29 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 16, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 16, 2023
…126934)

flutter/engine@fe24767...5cf141f

2023-05-16 godofredoc@google.com Add linux_clang_tidy builder. (flutter/engine#41990)
2023-05-16 ychris@google.com [ios_platform_view] only recycle maskView when the view is applying mutators (flutter/engine#41573)

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 rmistry@google.com,zra@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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
zanderso added a commit that referenced this pull request May 16, 2023
zanderso added a commit that referenced this pull request May 16, 2023
…plying mutators" (#42080)

Reverts #41573

Crashing on Framework CI
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 16, 2023
zanderso pushed a commit to flutter/flutter that referenced this pull request May 16, 2023
…sions) (#126961)

Manual roll requested by zra@google.com

flutter/engine@fe24767...1c775e3

2023-05-16 zanderso@users.noreply.github.com Revert "[ios_platform_view]
only recycle maskView when the view is applying mutators"
(flutter/engine#42080)
2023-05-16 gspencergoog@users.noreply.github.com [macOS] Wait for
binding to be ready before requesting exits from framework
(flutter/engine#41753)
2023-05-16 gspencergoog@users.noreply.github.com [linux] Wait for
binding to be ready before requesting exits from framework
(flutter/engine#41782)
2023-05-16 jacksongardner@google.com Initial support for images in
Skwasm (flutter/engine#42019)
2023-05-16 jacksongardner@google.com Use new `unresolvedCodePoints` API
from skia. (flutter/engine#41991)
2023-05-16 jason-simmons@users.noreply.github.com Convert public API
NativeFieldWrapper classes to abstract interfaces (flutter/engine#41945)
2023-05-16 737941+loic-sharma@users.noreply.github.com [Windows] Add
force redraw to the C++ client wrapper (flutter/engine#42061)
2023-05-16 godofredoc@google.com Fix drone_dimension
host_engine_builder. (flutter/engine#42068)
2023-05-16 godofredoc@google.com Add linux_clang_tidy builder.
(flutter/engine#41990)
2023-05-16 ychris@google.com [ios_platform_view] only recycle maskView
when the view is applying mutators (flutter/engine#41573)

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 rmistry@google.com,zra@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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@cyanglaz cyanglaz deleted the maskviewpool_regression branch May 17, 2023 18:41
auto-submit bot pushed a commit that referenced this pull request May 22, 2023
…plying mutators #41573" (#42115)

The original PR (#41573) was reverted due to flutter/flutter#126951

The issue will be fixed in #42079

This needs to be landed after #42079

fixes: flutter/flutter#125620

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
zanderso added a commit that referenced this pull request May 23, 2023
CaseyHillers pushed a commit to CaseyHillers/flutter that referenced this pull request May 24, 2023
…lutter#126934)

flutter/engine@fe24767...5cf141f

2023-05-16 godofredoc@google.com Add linux_clang_tidy builder. (flutter/engine#41990)
2023-05-16 ychris@google.com [ios_platform_view] only recycle maskView when the view is applying mutators (flutter/engine#41573)

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 rmistry@google.com,zra@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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
CaseyHillers pushed a commit to CaseyHillers/flutter that referenced this pull request May 24, 2023
…sions) (flutter#126961)

Manual roll requested by zra@google.com

flutter/engine@fe24767...1c775e3

2023-05-16 zanderso@users.noreply.github.com Revert "[ios_platform_view]
only recycle maskView when the view is applying mutators"
(flutter/engine#42080)
2023-05-16 gspencergoog@users.noreply.github.com [macOS] Wait for
binding to be ready before requesting exits from framework
(flutter/engine#41753)
2023-05-16 gspencergoog@users.noreply.github.com [linux] Wait for
binding to be ready before requesting exits from framework
(flutter/engine#41782)
2023-05-16 jacksongardner@google.com Initial support for images in
Skwasm (flutter/engine#42019)
2023-05-16 jacksongardner@google.com Use new `unresolvedCodePoints` API
from skia. (flutter/engine#41991)
2023-05-16 jason-simmons@users.noreply.github.com Convert public API
NativeFieldWrapper classes to abstract interfaces (flutter/engine#41945)
2023-05-16 737941+loic-sharma@users.noreply.github.com [Windows] Add
force redraw to the C++ client wrapper (flutter/engine#42061)
2023-05-16 godofredoc@google.com Fix drone_dimension
host_engine_builder. (flutter/engine#42068)
2023-05-16 godofredoc@google.com Add linux_clang_tidy builder.
(flutter/engine#41990)
2023-05-16 ychris@google.com [ios_platform_view] only recycle maskView
when the view is applying mutators (flutter/engine#41573)

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 rmistry@google.com,zra@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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
cyanglaz pushed a commit to cyanglaz/engine that referenced this pull request Jun 13, 2023
auto-submit bot pushed a commit that referenced this pull request Jun 13, 2023
…plying mutators #42115" (#42823)

Relands #42115, which was reverted in #42231 due to a crash in the framework test.

The crash is due to a memory management issue that I fixed it in this PR, I also added a scenario test to catch the crash.

fixes: flutter/flutter#125620

See also: orignal PR #41573 for more details.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
cyanglaz pushed a commit to cyanglaz/engine that referenced this pull request Jun 20, 2023
…plying mutators flutter#42115" (flutter#42823)

Relands flutter#42115, which was reverted in flutter#42231 due to a crash in the framework test.

The crash is due to a memory management issue that I fixed it in this PR, I also added a scenario test to catch the crash.

fixes: flutter/flutter#125620

See also: orignal PR flutter#41573 for more details.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
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 platform-ios
Projects
None yet
4 participants