Answer the question
In order to leave comments, you need to log in
Performance degradation in Android app due to GC?
In a typical piece of code, I have a performance drop of 5 seconds.
for (int i = 0; i < list.size(); i++){ \\ size ~ 30k
String str = list.get(i);
float strWidth = paint.measureText (str);
}
for (int i = 0; i < list.size(); i++){ \\ size ~ 30k
String str = list.get(i);
str = "a very very very long string";
float strWidth = paint.measureText (str);
}
Answer the question
In order to leave comments, you need to log in
If accuracy is not important, then you can do this:
float symWidth = paint.measureText("X");
for (int i = 0; i < list.size(); i++){ \\ size ~ 30k
String str = list.get(i);
float strWidth = symWidth * str.length;
}
The problem is most likely all the same in get and the loop. And the second example does not slow down because get does not happen - optimization. The cycle itself may not even occur.
I'll comment out the line with measureText in 1 example and everything is ok, it works fast.
Rendered Strings str; and int size = list.size() per loop - didn't help. I parallelized the code using AsyncTask, it did not help (each thread processed a separate part of the list). I also tried an array for the place of the list, and the file stream.readLine () does not help.
Is the measureText function slow?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question