Skip to content

Automatic/scalable shader warm-up #32170

Closed as not planned
Closed as not planned

Description

@liyuqian

Current status: #32170 (comment)


Although Flutter's current shader warm-up process is theoretically able to eliminate all shader compilation jank, it requires too much expertise and time to find all draw operations for such process.

We shall find a more automatic and scalable way of finding those draw operations to compose a custom warm-up process. That should allow average developers without much Skia knowledge to eliminate the shader compilation on their own. That should also save Flutter engineers a lot of time as they'll no longer have to manually analyze the janky frame.

Note that this issue affects iOS devices more significantly than Android devices because Android has binary shader persistent cache while iOS doesn't.

We have a staged plan to roll this out, and we're actively working on it.

  • SkSL-based shader warmup
  • Test-based shader warmup
  • In the long term, we'd like to create a solution that requires 0 extra effort from developers, and handles all cases that may have never been encountered during any tests or warmups. For example, use the CPU backend when GPU backend needs warm-up.

Related issue: #813, #31881

Activity

  1. added
    c: performanceRelates to speed or footprint issues (see "perf:" labels)
    on May 6, 2019
  2. self-assigned this
    on May 6, 2019
  3. added this to the April 2020 milestone on Aug 7, 2019
  4. eseidelGoogle commented on Aug 22, 2019

    @eseidelGoogle
    Contributor

    My understanding is that customer: dream is requesting a solution for their setup by end of November at least. I'm not sure if this is the right bug to track that or not?

  5. liyuqian commented on Aug 23, 2019

    @liyuqian
    ContributorAuthor

    @eseidelGoogle : Yes, we just had a meeting this week with customer: dream and Skia. Here's the plan that we've discussed (please "goto" flutter-compile-janks internal doc for more details):

    1. In the very short term, we’ll still use the old PaintingBinding.shaderWarmUp. However, we’ll not spend more sources on SKP based tools or solutions because the SKP capture itself is quite problematic:
    2. In the short term, we’ll work on SkSL to handle the request from customer: dream.They have only a very limited set of devices and drivers, so the variance of SkSL may already be small without any work from Skia. This solution require some work from Flutter, but it should free up a lot of our time later compared to manual PaintingBinding.shaderWarmUp.
    3. In the medium term, we’ll work on driver tests. Currently, this work is blocked by “Make driver test work without a host Make some driver-like test work without a host, in release mode #38329”. This solution would utilize a lot of work (on driver tests) that Flutter has to do anyway, so the marginal cost for Flutter/Skia is low. This solution also has relatively low developer cost and feasibility risk. And this solution is applicable to most platforms and devices, with little maintenance work due to Skia upgrade.
    4. In the long term, we’ll use the CPU backend when GPU backend needs warm-up.
  6. eseidelGoogle commented on Aug 26, 2019

    @eseidelGoogle
    Contributor

    Question: Do we need a 4 stage plan, or can we trade some short/medium term pain for doing fewer stages and skip one or more of these and earlier achieve the desired end result? FYI @Hixie

    Or maybe all of these stages are just separate parts of the desired end result and not throw-away work?

  7. liyuqian commented on Aug 26, 2019

    @liyuqian
    ContributorAuthor

    Quick update: stage 1 might be a past stage as we learnt that it may not be able to satisfy our clients next workload (at least 18 new shaders) in time. I'm now mainly investigating stage 2, which might not be re-usable in the long term but I really don't think stage 3 is possible before the deadline of customer: dream in September: I still don't see any estimation when stage 3's first blocker #38329 could be resolved.

  8. liyuqian commented on Aug 28, 2019

    @liyuqian
    ContributorAuthor

    Skia has estimated that their work on stage 2 SkSL will take about 0.5 to 1 week. They're checking priorities to see when this could happen.

  9. eseidelGoogle commented on Sep 3, 2019

    @eseidelGoogle
    Contributor

    @liyuqian Do we have any updates here to share with customer: dream?

  10. liyuqian commented on Sep 4, 2019

    @liyuqian
    ContributorAuthor

    The last update is on an email sent out last Friday (08/30) that CC'ed flutter-team and "customer: dream":

    Brian Osman is going to do the Skia change this week. I'll follow on that to give a proof of concept probably by next week.

  11. liyuqian commented on Sep 9, 2019

    @liyuqian
    ContributorAuthor

    Update: Skia has added the API (https://skia-review.googlesource.com/c/skia/+/239438). I'm going to prototype the Flutter change this week.

  12. added
    engineflutter/engine related. See also e: labels.
    on Sep 10, 2019
  13. added a commit that references this issue on Sep 12, 2019
  14. 213 remaining items

  15. esDotDev commented on Jan 26, 2022

    @esDotDev

    Has there been any consideration to doing this in more of a JIT way?

    Historically, on platforms like Unity or Flash, we have solved this issue by showing some invisible components in frame 1, while our splash screen is showing, so their shaders/textures are uploaded to gpu. Then, when they appear in the app for the first time, they are already cached and ready to go, everything is 60fps butter. Users don't notice anything, except maybe a small stutter on the preload animation and an extra 100-500ms of startup time.

    Seems like we could have a widget, that could take a stack of items, and cache all the shaders created from those items. Then write those down to disk. You could have a full 1000ms to do this, it would be no problem, and developers would happily make that tradeoff.

    Then all of this complexity becomes something as simple as sticking a widget on your splash page, with some child widgets, and waiting until its cache is complete. You also would get device-specific shaders this way, which seems simpler than dealing with myriad edge cases. It also does not bloat the file size of the download.

    Obviously developers would need to be careful with views that initiate network calls or other actions when mounted, but that is a much easier problem to solve, then all of this crazy build process and bundling complexity.

  16. dnfield commented on Jan 26, 2022

    @dnfield
    Contributor

    Yes, that has been considered, but it turns out that it's very difficult to capture just the right shaders that Skia will create for the specific things your app will draw. This gets very difficult to maintain, and it slows down startup time which our customers care about.

  17. talksik commented on Dec 29, 2022

    @talksik

    no solution yet? I started building with flutter desktop and noticed the transition jank of animations way later.

    been years with this issue right?

  18. Timmmm commented on Dec 29, 2022

    @Timmmm

    They have tried various unsatisfying hacks like profile-guided precompilation, but it looks like they're finally started working on a real solution:

    Impeller is a replacement for Skia that won't dynamically construct and compile shaders at runtime. Not at all ready yet but I'm very glad they've finally bit the bullet. The end is in sight at least!

  19. zanderso commented on Aug 11, 2023

    @zanderso
    Member

    SkSL caching and warm-up is no longer the approach the team is pursuing to solve early-onset jank.

  20. ghenry commented on Aug 11, 2023

    @ghenry
  21. Hixie commented on Aug 11, 2023

    @Hixie
    Contributor

    Our new graphics backend, Impeller, doesn't compile shaders on startup (it doesn't compile them at runtime at all), so there's no need to warm up shaders any more once Impeller is available. So the plan is to get Impeller working on as many platforms as we can. It's on by default on iOS now, Android is next, then we'll look at the desktop platforms. macOS should be relatively easy. Windows might be tricky because of DirectX. I forget the state of Linux and web regarding Impeller.

    Once Impeller is more widely deployed we'll remove the old shader warm-up logic (see #132418).

  22. acoutts commented on Aug 11, 2023

    @acoutts

    Can we continue to use sksl warmup in the meantime or does it not have any effect for iOS now?

  23. chinmaygarde commented on Aug 12, 2023

    @chinmaygarde
    Contributor

    @acoutts:

    Can we continue to use sksl warmup in the meantime or does it not have any effect for iOS now?

    Packaging SKSL has no effect on iOS. You can continue to do so but it will not affect rendering at all.

    @m-j-g (in a comment that has since been deleted but I got a GitHub email notification for):

    Worth noting that impeller is currently broken on the latest version of iOS, 16.6...

    Assuming you are talking about #131319. This does not affect Impeller at ToT or in 3.13. It affects all versions of the legacy renderer. We are still trying to wrap our heads around how iOS behavior changed so drastically in a point release. But we know what fixes the issue (since Impeller already doesn't exhibit it at ToT) and are trying to figure out how/if we should backport it and investigate the same fix in the legacy renderer. If you are aware of an Impeller specific performance issue however, please file a bug and we'll investigate it immediately.

  24. github-actions commented on Aug 26, 2023

    @github-actions

    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.

  25. locked as resolved and limited conversation to collaborators on Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work listc: performanceRelates to speed or footprint issues (see "perf:" labels)customer: crowdAffects or could affect many people, though not necessarily a specific customer.engineflutter/engine related. See also e: labels.perf: speedPerformance issues related to (mostly rendering) speedteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions