Driven by curiosity, let’s see if the performance of Android Jetpack Compose 1.5.1 has been improved?

Preface

It has been some years since Android Jetpack Compose made its debut at the Google I/O conference in 2019 and released the 1.5.1 stable version in September 2023, but the performance of Compose is still criticized by developers today.

This article is mainly to satisfy the author's curiosity. By the way, I will use the Perfetto tool to test it with everyone. Is the newly released version 1.5.1 really improved in performance as officially stated?

Preparation

  • AndroidStudio:Android Studio Giraffe | 2022.3.1 Patch 1
  • A Google Pixel 4 mobile phone: equipped with Android 12 system, turn on the developer options, turn on the HWUI presentation mode, select to display as a bar chart on the screen, and turn on the display refresh rate;
  • A list App implemented using the Android Jetpack Compose LazyColumn component, integrating Didi’s open source DoKit development assistant.

Test target

Compare the performance of the LazyColumn component of Android Jetpack Compose 1.4.1 and 1.5.1 versions . In fact, starting from 1.3.0, Compose has reconstructed the Modifier system and introduced Modifier.Node as a higher-performance replacement for Modifier.composed. However, this process does not happen overnight, and it takes time to gradually complete the replacement. Due to limited time and energy, the author will not test and compare other versions such as 1.3.0.

Warm reminder: Android officially recommends that we use the Compose Bill of Materials (BoM) to manage all Compose library versions by specifying the BoM version. Click here to view the

correspondence table between BOM and Compose library versions . 1.4.1 corresponds to 2023.04.01, 1.5.1 corresponds to 2023.09.00


Test steps

  1. Write a Shell script and use the adb shell swipe command to simulate constantly sliding back and forth on the LazyColumn component interface;
  2. Use the record_android_trace auxiliary script officially provided by Perfetto to record the trace file, which lasts about 10 seconds and is recorded 10 times for each version;
  3. Use Perfetto UI to open the recorded trace file, record and count the android_frame_timeline_metric indicator data and summarize it into a table;

image.png

image.png

1694937346615.gif.gif

The interface of the LazyColumn component is not very complicated and is a code copied from the official Jetchat project. Looking at the animation, you can see that the screen refresh rate and DoKit frame rate in the upper left corner have not changed.

Test Data

Obtain android_frame_timeline_metric indicator data by using Perfetto and summarize it (measured 10 times every 10 seconds), where total_frames is the total number of frames of the application, missed_frames is the number of dropped frames of the application, and fps is the frame rate = total_frames/time (seconds)

Maybe the testing method is not very reasonable (but it is very convenient to test with scripts). If there is a better way, you are welcome to give me your advice.

Android Jetpack Compose 1.4.1

A screenshot of the test data part is as follows:

image.png

android_frame_timeline_metric indicator data

image.png

process timieline

Summary of data measured 10 times for 10 seconds each time:

serial number total_frames missed_frames fps
1 787 49 78.7
2 774 45 77.4
3 777 50 77.7
4 787 48 78.7
5 788 52 78.8
6 798 43 79.8
7 778 48 77.8
8 794 46 79.4
9 777 50 77.7
10 783 50 78.3

image.png

image.png

average frames Average number of dropped frames Average frames dropped per second average frame rate Average frame loss rate
784.3 48.1 4.81 78.4 5.77%

Note: Average frame loss rate = average number of frames lost / (average number of frames + average number of frames lost)

Android Jetpack Compose 1.5.1

A screenshot of the test data part is as follows:

image.png

android_frame_timeline_metric indicator data

image.png

process timieline

Summary of data measured 10 times for 10 seconds each time:

serial number total_frames missed_frames
1 807 30
2 825 23
3 825 19
4 832 13
5 840 8
6 830 13
7 838 8
8 842 7
9 846 10
10 837 8

image.png

image.png

average frames Average number of dropped frames Average frames dropped per second average frame rate Average frame loss rate
832.3 13.9 1.39 83.2 1.64%

Note: Average frame loss rate = average number of frames lost / (average number of frames + average number of frames lost)

Data comparison

Compose version average frames Average number of dropped frames Average frames dropped per second average frame rate Average frame loss rate
1.4.1 784.3 48.1 4.18 78.4 5.77%
1.5.1 832.3 13.9 1.39 83.2 1.64%

Obviously, using the same model and the same test code, 1.5.1 has a higher frame rate and fewer frame drops than 1.4.1. Although it cannot be said to be far ahead, it is indeed a significant improvement, and it is also obvious when compared to Timeline. .

image.png

Note: You may think that the short test time or the small number of tests results in unreasonable small sample data, but in fact, the author found after many tests (extending the time and increasing the number of tests) that the data gap between the two versions is basically This is almost the case on Google Pixel 4 with Android 12 system. Due to space limitations, we do not show too much data. Friends who are interested and have time can test it by themselves. If possible, add more versions and models for comparison.

in conclusion

Due to limitations in test model, time and energy, this test is not rigorous, and the test data is for reference only. However, this small sample data can still be used to answer the questions raised at the beginning of this article:


The performance of Android Jetpack Compose 1.5.1 has been significantly improved, and the experience is smoother. It is recommended that everyone upgrade quickly.


As Android officials say, Android Jetpack Compose works hard and the performance is getting better and better.

What? Haven’t used Jetpack Compose yet? This is not important. Programmers must also learn to jump out of the technical perspective and examine life from a more macro perspective. Life is only a few decades. Cherish the present, embrace the future, and keep up with changes.

grateful

Guess you like

Origin blog.csdn.net/xiangang12202/article/details/132957549