Flutter architecture - threading model

Flutter's architecture is divided into framework, engine and embedder layer (Embedder), where the embedder layer embeds Flutter for each platform. The complete architecture diagram of Flutter is as follows:
insert image description here
The isolation in Flutter is implemented through a thread in the engine layer, but the creation and management of the Flutter engine thread is in charge of the embedder, which means that the embedder is the intermediate code for porting the platform engine . The operating architecture diagram of the Flutter engine is as follows:
insert image description here
There are 4 Runners in the embedder, and each engine corresponds to a UI Task Runner, GPU Task Runner, and IO Task Runner, but all engines share a Platform Runner.

  • Platform Task Runner
    Platform Task Runner is the main Task Runner of the Flutter engine, because the API of the platform can only be called in the main thread, so it corresponds to the main thread on Android. Platform Task Runner can not only handle the interaction of the Native platform, but also interact with the Flutter engine. When each Flutter engine is created, a Platform thread is created for the Platform Task Runner to use. Even if the Platform thread is blocked, it will not directly cause the Flutter application to freeze. Even so, it is not recommended to perform time-consuming operations in Platform Task Runner, and it may be forcibly killed by the system if stuck for a long time.
  • UI Task Runner
    UI Task Runner mainly processes code from Dart Root isolate, tells Flutter engine final rendering, Native Plugins messages, timers (delayed tasks), microtasks (microtasks), asynchronous I/O operations, file handles, etc. .
  • GPU Task Runner
    The GPU Task Runner is used to execute calls related to the device GPU. The thread that the GPU Task Runner runs corresponds to the sub-thread of the platform, and runs on a different thread from the UI Task Runner. If the GPU Task Runner takes too long, it will also cause the Flutter application to freeze. So in GPU Task Runner, time-consuming operations cannot be performed.
  • IO Task Runner
    The thread run by IO Task Runner is also a child thread of the corresponding platform. In the development of Flutter, when both the UI Task Runner and the GPU Task Runner are overloaded, it is necessary to use the IO Task Runner to perform some pre-processing read operations, and then report to the GPU Task Runner. Because only the GPU Task Runner can touch the GPU, the IO Task Runner is equivalent to the assistant of the GPU Task Runner.

Guess you like

Origin blog.csdn.net/Memory_of_the_wind/article/details/130967610