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

A couple of interesting findings #4

Open
sroddy opened this issue Mar 3, 2021 · 7 comments
Open

A couple of interesting findings #4

sroddy opened this issue Mar 3, 2021 · 7 comments

Comments

@sroddy
Copy link

sroddy commented Mar 3, 2021

Hi,
thank you for the amazing preliminary work in tackling this issue with this workaround.

I have a couple of hints to share with you regarding the best approach to perform the warmup routine as fast and efficiently as possible:

  1. The animations can be stacked, you don't need to play them sequentially. Even more I've discovered that you can also stack the same animation twice o three times with a little delay between them in order to maximize the chance of hitting all the frames and thus all the needed frames.
  2. You can place the warmup overlays below all the other visible overlays, as long as you create the OverlayEntry with maintainsState = true.
  3. if you instead apply a transform that moves your overlay entry outside the screen, the shaders will be optimized away.
  4. You can actually execute all the routine inside a completely separate engine. The interesting thing is that this enables you to keep the "real" flutter view that you are displaying completely responsive even during this animation dance. Below some example code to possibily launch early inside the appdelegate:
    let engine = FlutterEngine(name: "warmup")
    engine.run(withEntrypoint: "warmup")
    let warmupController = FlutterViewController(engine: engine, nibName: nil, bundle: nil)

    
    let rootBounds = controller.view.bounds
    warmupController.view.frame = rootBounds.applying(.init(translationX: rootBounds.width, y: 0))
    controller.addChild(warmupController)
    controller.view.addSubview(warmupController.view)
    warmupController.didMove(toParent: controller)
    
    DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(15)) {
      warmupController.willMove(toParent: nil)
      warmupController.view.removeFromSuperview()
      warmupController.removeFromParent()
    }
@theniceboy
Copy link

Literally life saving

@danReynolds
Copy link
Owner

@sroddy Awesome stuff! Would you be interested in exploring reworking this one or creating a separate lib that devs can use to easily take advantage of these findings? I'd be happy to collaborate and offer review although I'll need to ramp up to things like instantiating a new Flutter Engine, never delved into that.

@DavideDessi319
Copy link

DavideDessi319 commented Mar 3, 2021

I'm following the updates on this package very closely as it seems to be the only option to fix the Metal jank problem, at least until the Flutter team finds a solution. These findings are awesome, I'd really like to help implementing things if I could, but I don't have the experience to work with the engine..I really hope you guys and other collaborators will take interest in making this package even more powerful, it's really the only hope for now it seems

@ldasilva-net
Copy link

4. You can actually execute all the routine inside a completely separate engine. The interesting thing is that this enables you to keep the "real" flutter view that you are displaying completely responsive even during this animation dance. Below some example code to possibily launch early inside the appdelegate:

this discovery with the new feature for Multiple Flutter Engines practically without cost (https://flutter.dev/docs/development/add-to-app/multiple-flutters) is the perfect combination. We can have an Engine always alive only for warmup animations, so we can trigger there a flow that warmup all the animations without modifying any of our real views

@danReynolds
Copy link
Owner

4. You can actually execute all the routine inside a completely separate engine. The interesting thing is that this enables you to keep the "real" flutter view that you are displaying completely responsive even during this animation dance. Below some example code to possibily launch early inside the appdelegate:

this discovery with the new feature for Multiple Flutter Engines practically without cost (https://flutter.dev/docs/development/add-to-app/multiple-flutters) is the perfect combination. We can have an Engine always alive only for warmup animations, so we can trigger there a flow that warmup all the animations without modifying any of our real views

That sounds great! Do you have any examples where you warmup an animation you could share? I'm sure the community would really appreciate it.

@JayPerfetto
Copy link

I'm sorry to sound like a noob here but can anyone please explain how one uses the code in the main response?

Thank you,
Jason

@daveshirman
Copy link

I second this. The example code above gives no context about where to put it at all.

An example in context (i.e which app-code file /lifecycle event), with the navigator push/pop warm-up would be most appreciated if anyone has one they could share please.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants