DEV Community

flfljh
flfljh

Posted on • Edited on

First Step in Performance Analysis: Understanding Thread Sequencing

First Step in Performance Analysis: Understanding Thread Sequencing

When analyzing the performance of Flutter applications, developers need to capture application traces using profiling tools and analyze these traces. Flutter's rendering process relies on several critical threads. This guide introduces these essential threads and their sequence in the rendering workflow.

HarmonyOS Next introduces a new thread sequencing model with features like a high-concurrency task pool, worker threads, and a main thread that avoids blocking I/O operations. This model aims to optimize performance by intelligently distributing tasks across different thread types, minimizing delays and improving responsiveness, especially in I/O-intensive operations.
Here's a breakdown of the key components:
Main Thread:
Handles UI services and non-time-consuming tasks. It now shares the system's I/O thread pool, preventing it from being blocked by I/O operations.
High-Concurrency Task Pool:
Designed for time-consuming tasks, this pool encapsulates task execution and manages module loading, eliminating the need for manual thread lifecycle management.
Worker Threads:
Used for resident tasks, CPU-intensive operations, and long-running processes. HarmonyOS NEXT has a limit of 64 worker threads.
FFRT (Fast Forward Rendering Task) Task Pool:
A specialized pool for rendering tasks.
This new thread sequencing model in HarmonyOS Next is designed to address performance bottlenecks, especially in scenarios like instant messaging where I/O operations and data processing can lead to delays. By offloading these tasks to dedicated threads, the system aims to provide a more responsive and smoother user experience.

Analysis Tools

Commonly used tools include:

Recommended Tool: DevEco Studio Profiler

For usage instructions, see:

DevEco Profiler Tool Introduction

Thread Sequence

After mastering the profiling tools, you can capture traces of Flutter applications. Traces contain all threads during application runtime. For effective analysis, bookmark and arrange threads in the following order:

Bookmarked Threads Explained

  1. VSyncGenerator

    Software Vsync signal generator that provides frame synchronization capabilities.

  2. DVSync-app

    Delivers software Vsync signals to the application.

  3. mmi_service

    Handles multimodal input events triggered by touchscreen interactions.

  4. Main Application Thread

    The primary thread matching the application process ID and name.

    Hosts platform-level operations and plugin code execution.

  5. flutter'PointerEvent'

    Thread transferring touch events from the main thread to the UI thread for processing.

    (May not always appear in traces).

  6. 1.ui (UI Thread)

    Executes Dart code in the Dart VM.

    • Processes developer code and framework-generated logic
    • Builds the layer tree (device-independent rendering commands)
    • Transfers layer tree to the raster thread Critical: Never block this thread! Appears at the bottom of performance layers.
  7. 1.raster (Raster Thread)

    Processes the layer tree and communicates with the GPU.

    • Executes Skia graphics library operations
    • Performs rasterization for the GPU (runs on CPU)
    • Appears at the top of performance layers. Note: Slowdowns indicate issues in Dart code logic.
  8. DVSync-rs

    Provides software Vsync signals to the Render Service (RS) process.

  9. render_service

    Main thread of the RS process (first stage of display processing).

  10. RSUniRenderThread

    RS process thread (second stage of display processing).

  11. RSHardwareThread

    RS process thread (third stage of display processing).

  12. dpu_gfx_primary

    Hardware DPU (Display Processing Unit) signal thread.

Top comments (0)