Currently, Android's EditText is extremely slow when dealing with a huge amount of lines of text (10000+). It appears like this slowdown is partially due to the fact that EditText supports spans, and primarily due to the fact that EditText is calculating the width of each line, which is very expensive. Are there any faster alternatives to EditText, or a way to optimize it to make it usable?
EDIT: Method traces are as follows:
android.text.StaticLayout.generate: 99.1% CPU time inclusive, 8.8% exclusive (1 call)
android.text.Layout.getParagraphSpans: 28% inclusive, 1.1% exclusive (4686 calls)
android.text.MeasuredText.setPara: 20.6% inclusive, 1.6% exclusive (2343 calls)
android.text.MeasuredText.addStyleRun: 18.6% inclusive, 1.1& exclusive (2343 calls)
android.text.SpannableStringBuilder.getSpans: 15% inclusive (of parent calls), 56.7% inclusive (of all calls, 47.3% of which are from android.text.Layout.getParagraphSpans, 26% are from android.text.MeasuredText.setPara, 26% are from android.text.StaticLayout.generate)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…