8000 ☂️ Lightweight Flutter Engines · Issue #72009 · flutter/flutter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

☂️ Lightweight Flutter Engines #72009

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 8000 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

Closed
19 of 29 tasks
gaaclarke opened this issue Dec 9, 2020 · 35 comments
Closed
19 of 29 tasks

☂️ Lightweight Flutter Engines #72009

gaaclarke opened this issue Dec 9, 2020 · 35 comments
Labels
a: existing-apps Integration with existing apps via the add-to-app flow engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project perf: memory Performance issues related to memory platform-android Android applications specifically platform-ios iOS applications specifically team-engine Owned by Engine team

Comments

@gaaclarke
Copy link
Member
gaaclarke commented Dec 9, 2020

Description

This meta issue proposes an array of improvements to Flutter for supporting customers who want to use multiple Flutter instances in an app, focused on the Add-to-app use case. It includes improvements for performance and ease-of-use.

Design doc

http://flutter.dev/go/multiple-engines

Phase 1

Share Engine Components

iOS

Android

Shared

Phase 2

Share Engine Components

More performance tightening

FlutterView / FlutterEngine integration

Tests

Cleanup

Phase 3

@gaaclarke gaaclarke added engine flutter/engine repository. See also e: labels. a: existing-apps Integration with existing apps via the add-to-app flow labels Dec 9, 2020
@xster xster changed the title Lightweight Flutter Engines ☂️ Lightweight Flutter Engines Dec 9, 2020
@xster xster added platform-android Android applications specifically platform-ios iOS applications specifically perf: memory Performance issues related to memory labels Dec 9, 2020 8000
@foxsofter

This comment has been minimized.

@xster
Copy link
Member
xster commented Jan 23, 2021

As a preliminary check on the current state on the engine repo head, on a Pixel 3 with 5 runs with a mixture of force gc before each step and not, using the default create counter app as a test sample, creating 10 engines vs 1 engine costs 0.83mb extra per engine, with the first normal engine costing an average of 35.3mb in my setup.

@xster
Copy link
Member
xster commented Jan 27, 2021

Looking like iOS will be 1.13MB per additional engine on engine repo master head

@xster
Copy link
Member
xster commented Feb 2, 2021

On the latest master head, the per engine overhead is just 180kB now for both Android and iOS. This matches our prototype more correctly.

@fengnudexiaoniao
Copy link
fengnudexiaoniao commented Mar 5, 2021

The memory is still increased by 32M(not ~180K ),when new Flutter instance in new FlutterViewController by FlutterEngineGroup(ios)

each additional Flutter instance in new FlutterViewController beyond the first instance ,
The memory is still increased by 32m, not ~180K,Did you really test it? Do you provide any supporting data

@xster
Copy link
Member
xster commented Mar 5, 2021

Running again on stable 2.0.1:

1 engine:
Screen Shot 2021-03-05 at 10 42 05 AM

2 engines:
Screen Shot 2021-03-05 at 10 42 55 AM

The 2 engine case happens to be smaller than the 1 engine case since it's within the margin of error. We took the 180kB measurement by taking many runs and taking the median number.

Also on the VM tracker:

1 engine:
Screen Shot 2021-03-05 at 10 46 14 AM

2 engines:
Screen Shot 2021-03-05 at 10 46 55 AM

It takes a bit of work to get the right number (and then de-noise it again by taking multiple runs). We have to remove the "Performance tool data" memory from both the before and after's dirty size to get the real application memory consumption. But you can see the ballpark at least.

Also note, the measured memory is the cost of the Flutter Engine supporting a second engine (which includes the Java/Obj-C bootstrapping classes, a second instance of the core C++ engine, a second Dart isolate etc) and the cost of a second Flutter Framework instance (all the Flutter Dart layers from Foundation to Material) in a minimal app. If you have a full Flutter application which consumes memory itself (such as reading files, downloading network resources etc) and then create a second instance of your application, it'll likely consume 2x the memory. It would be upon you, the user, to modularize your code to run separate code (such as via different entrypoints) to show separate UI on multiple Flutter instances as needed.

Also follow dart-lang/sdk#36097 for future plans on sharing Dart data between isolates and #72033 for potentially sharing image caches between Flutter instances.

If you share a simple reproduction project for your case, we can take a look to debug as well. It's very possible we have a bug as well.

@iLees

This comment has been minimized.

@gaaclarke
Copy link
Member Author

@iLees I pulled out your report in an issue so it can be investigated. ( #77621 )

@krmao

This comment has been minimized.

@iLees
Copy link
iLees commented Mar 12, 2021

@iLees I pulled out your report in an issue so it can be investigated. ( #77621 )

Fine, I get it.

@iprox
Copy link
iprox commented Mar 29, 2021

hi folks, according to the https://flutter.dev/docs/development/add-to-app/multiple-flutters

Warning: In 2.0.0, the use of platform views is not supported in conjunction with multiple Flutters. When a second Flutter instance is created, platform views will be globally disabled.

is it planned to remove the limitation above?

@krmao
Copy link
krmao commented Mar 29, 2021

now I have found few problems by used multi engine with android/ios:

  1. engines can't set initialRoute
  2. engines render need splash view if engine render slower while from one FlutterViewController push to another FlutterViewController, current release may delay 30ms and then push will ios looks like ok, android need transparent looks like ok but a little delay
  3. now ios releame every FlutterViewController with engines increase 11-13MB not 180k, android is about 3MB each FlutterViewActivity

@marziman
Copy link

Hello @gaaclarke can you please help us or am I wrong in this thread?

We have the following scenario:

  • From one Android/Flutter app, we need to draw UIs on 2 screens with different content
  • We are starting 2 Flutter Engines and want them to communicate with each other to share data, navigation state as they together make up one "logical bigger app".

Could be use the multiple Flutters feature for this?
Currently we are having 2 completely isloated FlutterEngines and same code loaded in both enignes.
We are than doing some kinda a IPC communication by native platform channels (message service) to make those 2 FlutterEngines know each other.

Your help would be much appreciated.
Thanks!
Mehmet

@yanwei49

This comment was marked as off-topic.

@krmao
Copy link
krmao commented Jul 6, 2022

android FlutterEngineGroup destroyEngine false, open FlutterActivity with this engine multi times,

SystemChrome.setSystemUIOverlayStyle only first time open FlutterActivity work

@martinsellergren
Copy link
martinsellergren commented Jun 6, 2023

I needed to share data between multiple flutter instances in an add-to-app scenario. Created a package to help with it: synced_bloc. A bloc that is synced across platform channels.

Snippet from the readme:

On native app startup, create (and cache) any flutter modules you have - including a dependency maintainer module. The dependency maintainer doesn't have any ui, it only creates and maintains dependency objects (sync master blocs!). It's running during the whole app lifecycle and provides dependencies to other modules/ native app. Anyone can access these dependencies by creating a sync subscriber.

@lubritto
Copy link
Contributor

Hello @gaaclarke, I found an interesting issue with the EngineGroups that is actually easy to reproduce and would like to understand if it's a known behavior or not.

On the MultipleFlutters example project, when adding any platform view (WebView, GoogleMaps) to the Flutter screen, everything works normally. But there's a bug happening when the first engine of the group was never loaded into a ViewController, when moving from one screen with PlatformView to another screen with/without platform view, the next engine crashes with EmptyScreen, and no logs on Native neither on Flutter.

To give a bit more context, in our project, we have a UI Less Engine that is always alive like an API to get some information from Flutter. We usually load it in the app startup to check if the deep link is available or not on the Flutter side before opening an engine, that's why this engine has no view controller attached to it.

I'm working to provide the minimum reproducible code soon.

@dodatw
Copy link
dodatw commented Jul 5, 2023

About FlutterEngineGroup + PlatfromView Crash, may be same issue #127168

@mkustermann
Copy link
Member

About FlutterEngineGroup + PlatfromView Crash, may be same issue #127168

#127168 has been fixed now.

@dodatw
Copy link
dodatw commented Oct 14, 2023

About FlutterEngineGroup + PlatfromView Crash, may be same issue #127168

#127168 has been fixed now.

Which version invlude this fixing?
I tried flutter 3.13.7 still can reporduce this issue.

@flutter-triage-bot flutter-triage-bot bot removed the triaged-engine Triaged by Engine team label Dec 20, 2023
@flutter-triage-bot
Copy link

This issue is marked P1 but has had no recent status updates.

The P1 label indicates high-priority issues that are at the top of the work list. This is the highest priority level a bug can have if it isn't affecting a top-tier customer or breaking the build. Bugs marked P1 are generally actively being worked on unless the assignee is dealing with a P0 bug (or another P1 bug). Issues at this level should be resolved in a matter of months and should have monthly updates on GitHub.

Please consider where this bug really falls in our current priorities, and label it or assign it accordingly. This allows people to have a clearer picture of what work is actually planned. Thanks!

@flutter-triage-bot
Copy link

This issue is marked P1 but has had no recent status updates.

The P1 label indicates high-priority issues that are at the top of the work list. This is the highest priority level a bug can have if it isn't affecting a top-tier customer or breaking the build. Bugs marked P1 are generally actively being worked on unless the assignee is dealing with a P0 bug (or another P1 bug). Issues at this level should be resolved in a matter of months and should have monthly updates on GitHub.

Please consider where this bug really falls in our current priorities, and label it or assign it accordingly. This allows people to have a clearer picture of what work is actually planned. Thanks!

@jonahwilliams jonahwilliams added P3 Issues that are less important to the Flutter project and removed P1 High-priority issues at the top of the work list labels Jul 15, 2024
@jonahwilliams
Copy link
Member

Given that most work has been complete here I think the meta issue has outlived its usefullness and I'm closing it. remaining work can be tracked in the individual bugs.

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: existing-apps Integration with existing apps via the add-to-app flow engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project perf: memory Performance issues related to memory platform-android Android applications specifically platform-ios iOS applications specifically team-engine Owned by Engine team
Projects
Status: Engineer reviewed
Development

No branches or pull requests

0