New issue
Advanced search Search tips

Issue 878529 link

Starred by 1 user

Issue metadata

Status: Assigned
Owner:
Cc:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug



Sign in to add a comment

AsyncTask get() blocks UI thread on background

Project Member Reported by smaier@chromium.org, Aug 28

Issue description

AsyncTask's get() function, when called from a UI thread, blocks the UI on a lower priority thread (right now, it's being block on a BACKGROUND priority thread, which is very low priority).

After auditing some of the get() callsites, they appear to be sensible locations to call get(), and a refactor to move them off get() might be difficult. Specifically, they tend to be places where a resource will be needed "soon-ish" and so the resource is warmed up on an AsyncTask. Eventually, the resource is actually needed, so they call get(), and the majority of the time the get() returns instantly. However, in the case where the AsyncTask hasn't already returned, it then blocks.

We have two possible solutions, which could both be implemented:
1) Calling get() tries to cancel the task if it is not in progress and runs it on the UI thread
2) Calling get() raised the priority of the thread the task is running on

One issue with these solutions is serial execution - if we call get on a task that is in a serial executor, we have to ensure we boost all tasks that are ahead of it in the queue.
 
Cc: torne@chromium.org
See PathUtils for one existing example of where we cancel the task and run it on the UI thread instead.
Cc: skyos...@chromium.org
Sounds good. Do we have any metrics that tell how often and how long the UI thread is blocked by get()?
We don't have any direct metrics - that sounds like a good idea. We could probably add a trace event in the get() function.

We have a related metric, which is ANRs from AsyncTask.get(), which can be seen here:

go/oijvt (if I remember correctly, this has some strange permissions on it, hopefully you have access)
Project Member

Comment 4 by bugdroid1@chromium.org, Aug 31

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/f7fa252dda85d1029158a87d0878c541e6f869c9

commit f7fa252dda85d1029158a87d0878c541e6f869c9
Author: Sam Maier <smaier@chromium.org>
Date: Fri Aug 31 22:43:17 2018

Android: Added TraceEvent to AsyncTask.get()

Bug: 878529
Change-Id: I01f8c6cb8fab2785f6eaf258c91edd6f3ef58736
Reviewed-on: https://chromium-review.googlesource.com/1195160
Commit-Queue: Sam Maier <smaier@chromium.org>
Reviewed-by: agrieve <agrieve@chromium.org>
Reviewed-by: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588192}
[modify] https://crrev.com/f7fa252dda85d1029158a87d0878c541e6f869c9/third_party/android_async_task/java/src/org/chromium/base/AsyncTask.java

Sign in to add a comment