I am investigating ways to improve performance in EditText
, specifically in regards to load times. When loading large documents of a few thousand words or more, calling setText
can freeze the UI for several seconds on some of my test devices and emulators.
In response, I have explored several possible solutions, none of which produce satisfactory results. I have tried to split large documents by paragraph, and load each paragraph into its own RecyclerView
or ListView
row. RecyclerView was completely hopeless due to a problem that causes jerky scrolling. ListView
provided great, almost immediate, load times, and pretty good scrolling (although not as a good as one EditText
block) but there is an issue where EditText
blocks inside rows lose focus when selected. I have also attempted to update an EditText
in sections from onProgressUpdate
in an AsyncTask
, hoping that the user could interact with the text as it loads in sections, but load times are largely unaffected.
The most promising avenue I have explored relates to changing the following element in AndroidManifest.xml
:
android:hardwareAccelerated="false"
I got the idea after watching the following segment from this YouTube clip on the Google Developers channel. When I switched on GPU Profile rendering, I discovered that the orange bar (representing "process time") was rocketing every time setText
was called. When I switched off hardware acceleration, setText
performance increased massively, although other areas (like scrolling) became much worse.
What I would like to understand is - why is this happening? Also, is there a way that I can use this information to further increase performance? Can I toggle hardware acceleration off and on again programatically simply?
It's worth mentioning some devices, like a Nexus 7 2013 running API 22, don't suffer any issues whatsoever when calling setText on large documents, whereas others really struggle with hardware acceleration on. I just want to understand what's going on better so I can attempt to fix it! Thanks.
EDIT:
Here is a link to a GitHub Repository for anyone to download one of my sample test apps to replicate the problems I listed above. I also have three videos I posted on the site demonstrating these issues, which I shall mirror below:
I have made three video demonstrations that show this app running on a
Huawei Honor Holly running KitKat
4.4.2 with the hardwareAccelerated
attribute set to true
in the
AndroidManifest
, then with the same phone with the same attribute
set to false
, and a separate Nexus 7 (2013) running Lollipop
5.1 with hardware acceleration enabled. GPU Profiling is on in each case.
Honor Holly - Acceleration
On
Honor Holly - Acceleration
Off
Nexus 7 (2013) - Acceleration
On
See Question&Answers more detail:
os