From 933e17949b0dd982a0dd362689e000f32c3abbe8 Mon Sep 17 00:00:00 2001 From: Alexander Blom Date: Mon, 13 Jun 2016 05:49:30 -0700 Subject: [PATCH] Run init on normal thread priority Summary: The default priority for AsyncTask is THREAD_PRIORITY_BACKGROUND which puts the thread in a limited cgroup that can utilize ~10% CPU time. Because the whole TTI depends on this task we should run it on a normal priority. The priority will be reset for the nest task and this has been true since donut: https://github.com/android/platform_frameworks_base/blob/donut-release/core/java/android/os/AsyncTask.java Reviewed By: astreet Differential Revision: D3417232 fbshipit-source-id: e1e35f82b35b31ff7ebf4fc59509ca2df21e2bdd --- .../java/com/facebook/react/XReactInstanceManagerImpl.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java index b0afbd536..782fd2542 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java @@ -26,6 +26,7 @@ import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.os.Process; import android.view.View; import com.facebook.common.logging.FLog; @@ -190,6 +191,12 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE; @Override protected Result doInBackground(ReactContextInitParams... params) { + // TODO(t11687218): Look over all threading + // Default priority is Process.THREAD_PRIORITY_BACKGROUND which means we'll be put in a cgroup + // that only has access to a small fraction of CPU time. The priority will be reset after + // this task finishes: https://android.googlesource.com/platform/frameworks/base/+/d630f105e8bc0021541aacb4dc6498a49048ecea/core/java/android/os/AsyncTask.java#256 + Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); + Assertions.assertCondition(params != null && params.length > 0 && params[0] != null); try { JavaScriptExecutor jsExecutor = params[0].getJsExecutorFactory().create();