-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Add FAQ entries. #54456
[Impeller] Add FAQ entries. #54456
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,3 +100,139 @@ | |
| as development progresses. | ||
| * How do you run `impeller_unittests` with Playgrounds enabled? | ||
| * Specify the `--enable_playground` command-line option. | ||
| * Describe Impeller in a Tweet. | ||
| * "Impeller is ahead-of-time (AOT) mode for rendering." | ||
| * Why did the Flutter team build Impeller? | ||
| * The short answer, for consistent performance, which could not be achieved | ||
| with Skia after years of effort by graphics experts. The longer answer... | ||
| * Flutter applications, via their use of Skia, were susceptible to the problem | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The longer form answer here reads a bit odd in bullet form. Usually bullets are separate points, but here it's just a set of paragraphs. Could it be reformatted to a single large bullet with text and line breaks?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, @sethladd mentioned the same thing thing in #54456 (comment). I'm going to reformat the entire doc in a later patch. |
||
| of jank (user-perceptible stuttering/choppiness in animations and | ||
| interactions) due to shader compilation. Such problems were [reported as | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe s/due to shader compilation/due to needing rendering shaders to be compiled on-demand before they could be executed/ or similar?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good clarification |
||
| early as 2015](https://github.com/flutter/flutter/issues/813). | ||
| * Shaders are tiny programs that run on the GPU when a specific combination of | ||
| rendering intent is requested by the application. Flutter's API is extremely | ||
| expressive. During the original design of Flutter's architecture, there was | ||
| an assumption that it was infeasible to statically determine ahead-of-time | ||
| the entire set of shaders an application might need. So, applications would | ||
| create and compile these shaders just-in-time. Once they were compiled, they | ||
| could be cached. | ||
| * But this led to the problem of jank during the initial run of performance | ||
| sensitive areas of the application when there were no cached shaders. | ||
| * Fortunately, early on, the team was able to predict the common shaders the | ||
| application was likely going to need. A generic ["warm | ||
| up"](https://github.com/flutter/flutter/pull/27660) phase was added where | ||
| these shaders were given a chance to be compiled and cached at the launch of | ||
| a Flutter application. | ||
| * As Flutter applications became more complex, the generic shader warmup was | ||
| no longer suitable for all apps. So the ability to specify shaders to warm | ||
| up was [exposed to end | ||
| users](https://api.flutter.dev/flutter/painting/ShaderWarmUp-class.html). | ||
| * But, this was exceedingly hard to do and also platform specific (iOS Metal, | ||
| Android OpenGL, Fuchsia Vulkan, etc.). So much so that only a handful of | ||
| engineers (who all worked on the Flutter Engine) could effectively build the | ||
| rendering intent that would warm up the right shaders. And these shaders | ||
| were specific to the app version. If the app was updated to add or remove | ||
| more features, the warmup routines were invalid and mostly just served to | ||
| slow down application startup. | ||
| * To make this process self-service, [a scheme was | ||
| devised](https://github.com/flutter/flutter/issues/53607) to run the | ||
| application and its tests during development in training phase, capture the | ||
| shaders, package them with the application, and during a new "warm up" | ||
| phase, pre-compile the shaders. | ||
| * Remember, these shaders were platform specific. The scheme detailed above | ||
| unfortunately moved the burden to developers. It also made the application | ||
| sizes a lot bigger since the shaders now had to be packaged with the | ||
| application. Application launch times were delayed as well. | ||
| * Even developers who went through these steps weren't always guaranteed | ||
| freedom from shader compilation jank. If some screens (and thus, their | ||
| shaders) were missed during training runs due to incomplete automated or | ||
| manual testing, jank could be experienced. For complex applications where | ||
| certain flows were blocked behind authentication or other restrictions, this | ||
| was an easy situation to get into. Also, some animation frames could be | ||
| skipped during training because jank during previous frames in the training | ||
| run. So training runs not only had to be run over the entire app, but also | ||
| multiple times (on all platforms) to ensure success. Moreover, applications | ||
| that were really effective at training began to run into egregiously high | ||
| first-frame times ([some as high as 6 | ||
| seconds](http://github.com/flutter/flutter/issues/97884)). Shaders captured | ||
| from training runs weren't fully guaranteed to be consistent across devices | ||
| on the same platform either and [bugs were | ||
| common](https://github.com/flutter/flutter/issues/102655#issuecomment-1115179271). | ||
| All the while the team was [desperately trying to | ||
| reduce](https://github.com/flutter/flutter/issues/84213) the number of | ||
| shader variants that might be required. | ||
| * Due to these reasons, developers abandoned this self-serve warmup mechanism. | ||
| For instance, no application in Google used this due to the all the problems | ||
| mentioned. | ||
| * Flutter began to get a reputation as being hard to write performant apps | ||
| with. Consistent performance that could be expected from frameworks like | ||
| UIKit on iOS. Sadly, this wasn't a completely unwarranted reputation at the | ||
| time. To us, the state of writing graphically performant apps with Flutter | ||
| wasn't good enough and frankly unacceptable. We needed to do better. | ||
| * Impeller was borne out the experience from these events. In additional to | ||
| the jank issues described above, there were other performance issues | ||
| inherent in the way Flutter held and used our original renderer. But, in | ||
| truth, the mandate to work on Impeller would never have materialized if it | ||
| weren't for the issue of shader compilation jank. In-spite of the massive | ||
| sunk cost of attempting all the workarounds shader complication jank that | ||
| prevented us from delivering our product requirement to deliver consistent | ||
| 60fps even at first-run. | ||
| * A very early look at how Impeller avoids the problems in the previous | ||
| renderer are [discussed in this | ||
| tech-talk](https://www.youtube.com/watch?v=gKrYWC_SDxQ). Our current | ||
| renderer is way more advanced today but that talk describes the very early | ||
| thinking, motivations, and decisions. | ||
| * We turned on Impeller by default for iOS in early 2023, and it has been in | ||
| production in the majority of iOS apps since then. It's currently, as of | ||
| 3.22 an opt-in option for Flutter on Android. | ||
| * Since we enabled Impeller on by default for iOS, we have seen the vast | ||
| majority of open issues around shader compilation causing jank to have been | ||
| fixed. We know there is more work to do, but we're encouraged by the results | ||
| we've been hearing from our customers. | ||
| * Today, Impeller outperforms the old renderer not only in worst-frame timed | ||
| benchmarks, but is also faster on average. | ||
| * What makes Impeller different, compared to Skia, for Flutter? | ||
chinmaygarde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * We want to start by saying Skia is amazing. We'd also never say Impeller is | ||
| better than Skia. It just works differently. The original design of Impeller | ||
| was based on collaboration with the Skia team and was greatly influenced by | ||
| their feedback. We also keep collaborating on an ongoing basis. Ideas such | ||
| as stencil-then-cover that Impeller now uses originated from Skia. Flutter | ||
| also continues to use Skia for text layout and its image codecs and has no | ||
| plans to migrate away from using those sub-components. We wholeheartedly | ||
| recommend Skia for most rendering needs. | ||
| * All of Impellers shaders are [manually authored and | ||
| compiled](https://github.com/flutter/engine/tree/0a8de3dd3285c0b64de47630a8218ae38b8e04e1/impeller#the-offline-shader-compilation-pipeline) | ||
| during build time and packaged with the Flutter engine. There is no runtime | ||
| shader generation, reflection, or compilation. Skia can and does generate | ||
| and compile shaders at runtime. | ||
| * By necessity, Impeller has a bounded set of shaders (< 50) that are known | ||
| ahead of time. Due to the way rendering intent is parameterized, Impeller | ||
| also needs way fewer shaders than Skia. All the graphics pipelines needed by | ||
| Impeller are ready well before the Flutter application's Dart isolate is | ||
| launched. Skia can generate and compile shaders during frame workloads | ||
| leading to worse worst-frame times. | ||
| * Because the processing of shaders in Impeller happens at build time when | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a minor nit, we are still compiling shaders at runtime, and may generate new PSOs on demand. But we don't have to go through a source -> source translation or reflection step, and on iOS we can use metal achive files which load much faster. The GPU is still jitting the shader though
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a good thing to mention. Is there a general notion we can give of the relative cost between PSO generation and the source->source translation? Like is it 10x cheaper?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 100x maybe?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on iOS in particular, it seems to be closer to "free"
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (The PSO generation)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And important to point out this isn't an alternative, in the old route we go source -> source -> metal compiler (source) -> PSO. now we just go metal compiler (archive) -> PSO.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went back and forth quite a bit on this and adding backend specific nuance made things a whole lot more complicated. On Metal, we can use either AIR files or the new Metal Binary Archives which really move everything to be at build time. But have to resort to flinging strings around with OpenGL ES. So what happens before GPU microcode is generated is quite quite messy to explain. This seemed like a fine enough bit of context to tell the story. Should I add another FAQ entry perhaps? @zanderso From go/impeller-prototype, I found this screenshot of a trace I took where the cost of the shader library construction is separate from the PSO creation (the small pink trace at the end). I think in this version of Skia, this included source-to-source translation as well as the shader library construction we do here in Impeller. Even that last bit at the end, Impeller does before first frame (well variants are another matter I suppose).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, nevermind. In this case, there is an SKSL cache hit. Its even slower when there is no cached SKSL. This used to happen when the phone was rebooted and Metals caches weren't warmed up from previous runs. I was making that case that perfect SKSL caches were necessary but not sufficient for jank free operation because metalc literally had to do LLVM things and that was more than sufficient to blow our frame budgets. Such a mess and I've blocked away so much of this context in my head.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We, of course, never found this janky behavior on our benchmarks because we didn't reboot phones between runs to clear the internal metal caches. |
||
| compiling the engine, Impeller's binary size impact is a fraction as that of | ||
| Skia's. Since there is no shader compilation and reflection machinery at | ||
| runtime, Impeller [adds only around | ||
| 100kb](https://github.com/flutter/flutter/issues/123741#issuecomment-1553382501) | ||
| of binary size at runtime (compressed) even when all the generated shaders | ||
| are packaged in a Flutter engine. Removing Skia GPU (which includes the SKSL | ||
| shader compilation machinery) [reduces the binary size of the Flutter engine | ||
| by 17%](https://github.com/flutter/engine/pull/52748). That is to say, the | ||
| machinery to generate, parse, compile, and reflect shaders is larger than | ||
| the backend specific shaders themselves. Using an Impeller-only build leads | ||
| to much smaller Flutter engines. | ||
| * Impeller doesn't have a software backend unlike Skia. Instead, software | ||
| rendering using Impeller can be achieved using a Vulkan or OpenGL | ||
| implementation running in software using projects like SwiftShader, | ||
| LLVMPipe, etc. | ||
| * Where did Impeller get its name? | ||
| * Impeller began as a modest experiment to solve the problem of shader | ||
| compilation jank. After the theory of operation was settled on, the process | ||
| of hacking together a prototype began with a component tacked onto Flutter's | ||
| compositor. The compositor happens to be called "flow". Since impeller's | ||
| modify fluid flow, the name seemed apt. It's also an internal component and | ||
| perhaps 30 seconds were spent thinking of a name. | ||
| * Why Flutter's compositor is called "flow" is left as an exercise to the | ||
| reader. | ||

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.
Suggest s/Describe Impeller in a Tweet/Describe Impeller in less than 10 words/
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.
But thats literally what Seth asked 😄 !
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.
hah yes I did, but I like @mit-mit 's suggestion here :)