We found that it took more time for inflating layouts/views on Android Uthan Android T in our devices. So I make an experiment with pixel Phone.
- Firstly, I developed a demo app which just do inflate an specified layout. It included LinearLayouts/TextViews/Buttons/NumberPickers etc. And it'll output the total time the inflating took.
- Then, installed the demo into both pixel 4(Android T system) and pixel 7(Android U system). Do the inflating operation. We can find that in Android U, it took 2-3 times time than Android T even the CPU working in much high freq in pixel 7.
e.g. Inflating NumberPicker component: Pixel 7 inflating running on CPU 7 with freq 2.5GHz took about 2ms. Well Pixel 4 inflating running on CPU 6 with freq 1.8GHz took about 0.8ms.
We got the same conclusion between pixel and our own device. It also makes jank issues in some Apps.
PS:Folowing is my test code. And you can input any layout id to do inflate and calc the time.
private long testInflateSpeed(int rId) {
try {
long startTime = SystemClock.elapsedRealtime();
LayoutInflater inflater = getLayoutInflater();
inflater.inflate(rId, null);
long endTime = SystemClock.elapsedRealtime();
return (endTime - startTime);
} catch (Exception ex) {
Log.d("DEBUG_INFLATE", "testInflateSpeed failed", ex);
}
return -1;
}
So anybody knows if there is something wrong about android U? And how to make optimize?