Improve AyncTask throughput inside WidgetPreviewLoader

b/21133230
> Synchronized block was creating a bottleneck for the AsyncTasks.
> Remove calls that doesn't need to be synchronized outside synchronized block.
> Also removed setAlpha call as after the bottleneck was removed,
Inefficient alpha view usage alert started popping up in traceview.
Due to less jankness, removing the fadein animation doesn't have any
visible effect.

Link to lock congestion visualization:
https://x20web.corp.google.com/~hyunyoungs/no_crawl/traceview/traceview_lockcontention.html

Result: gfx-avg-jank delta = "-1"
Change-Id: If12817df0730f346cdba7e2f38f232eb9a4336c0
This commit is contained in:
Hyunyoung Song
2015-06-05 13:30:19 -07:00
parent a56eab41fb
commit f00d02b254
3 changed files with 21 additions and 11 deletions

View File

@@ -586,26 +586,26 @@ public class WidgetPreviewLoader {
protected Bitmap doInBackground(Void... params) {
Bitmap unusedBitmap = null;
// If already cancelled before this gets to run in the background, then return early
if (isCancelled()) {
return null;
}
synchronized (mUnusedBitmaps) {
// If already cancelled before this gets to run in the background, then return early
if (isCancelled()) {
return null;
}
// Check if we can use a bitmap
// Check if we can re-use a bitmap
for (Bitmap candidate : mUnusedBitmaps) {
if (candidate != null && candidate.isMutable() &&
candidate.getWidth() == mPreviewWidth &&
candidate.getHeight() == mPreviewHeight) {
unusedBitmap = candidate;
mUnusedBitmaps.remove(unusedBitmap);
break;
}
}
}
if (unusedBitmap == null) {
unusedBitmap = Bitmap.createBitmap(mPreviewWidth, mPreviewHeight, Config.ARGB_8888);
} else {
mUnusedBitmaps.remove(unusedBitmap);
}
// creating a bitmap is expensive. Do not do this inside synchronized block.
if (unusedBitmap == null) {
unusedBitmap = Bitmap.createBitmap(mPreviewWidth, mPreviewHeight, Config.ARGB_8888);
}
// If cancelled now, don't bother reading the preview from the DB
if (isCancelled()) {