1. Controlling build() cost:
- Repetitive and costly work in build() --> can be invoked frequently when ancestor Widgets rebuild. It can be invoked frequently when ancestor Widgets rebuild.
- Split them into different Widgets based on encapsulation, Avoid overly large single Widgets. Avoid calling setState() high up in the tree
2. Apply effects only when needed
3. Render grids and lists lazily
4. Build and display frames in 16ms for rendering on a 60Hz display. 60fps leads to a smooth visual experience.
5. Pitfalls
- Avoid using the Opacity widget
- Avoid putting a subtree in the builder function When using an AnimatedBuilder.
- Avoid clipping in an animation.
- Avoid using constructors with a concrete List of children (such as Column() or ListView())
6. Flutter’s threads
- Platform thread: Plugin code runs here
- UI thread: executes Dart code in the Dart VM (code that you wrote, and code executed by Flutter’s framework).Creates a layer tree sends to the raster thread to be rendered on the device. ---> Although you have no direct access to any other thread, your actions on the UI thread have performance consequences on other threads.
- Raster thread (previously known as the GPU thread): takes the layer tree and displays it by talking to the GPU (graphic processing unit).
- I/O thread: expensive tasks (mostly I/O)
Nhận xét