Permalink
Browse files

bump up priority of RN threads during startup

Reviewed By: shergin, yungsters

Differential Revision: D5002320

fbshipit-source-id: 8467370940d3742266b3bf319e9a38ae22eab98e
  • Loading branch information...
AaaChiuuu authored and facebook-github-bot committed May 5, 2017
1 parent 1dd7bc1 commit 82c4b9f0b756ad05416d800668c5dd3e08358d5e
@@ -742,7 +742,7 @@ private void runCreateReactContextOnNewThread(final ReactContextInitParams initP
@Override
public void run() {
try {
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
final ReactApplicationContext reactApplicationContext = createReactContext(
initParams.getJsExecutorFactory().create(),
initParams.getJsBundleLoader());
@@ -827,6 +827,26 @@ private void setupReactContext(ReactApplicationContext reactContext) {
}
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
mCurrentReactContext.runOnJSQueueThread(new Runnable() {
@Override
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
}
});
mCurrentReactContext.runOnNativeModulesQueueThread(new Runnable() {
@Override
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
}
});
if (mUseSeparateUIBackgroundThread) {
mCurrentReactContext.runOnUiBackgroundQueueThread(new Runnable() {
@Override
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
}
});
}
}
private void attachMeasuredRootViewToInstance(
@@ -142,8 +142,6 @@ public static MessageQueueThreadImpl create(
switch (spec.getThreadType()) {
case MAIN_UI:
return createForMainThread(spec.getName(), exceptionHandler);
case BACKGROUND_UI:
return startUIBackgroundThread(spec.getName(), spec.getStackSize(), exceptionHandler);
case NEW_BACKGROUND:
return startNewBackgroundThread(spec.getName(), spec.getStackSize(), exceptionHandler);
default:
@@ -177,29 +175,6 @@ public void run() {
return mqt;
}
public static MessageQueueThreadImpl startUIBackgroundThread(
final String name,
long stackSize,
QueueThreadExceptionHandler exceptionHandler) {
return startNewBackgroundThread(name, stackSize, exceptionHandler, true);
}
public static MessageQueueThreadImpl startNewBackgroundThread(
final String name,
QueueThreadExceptionHandler exceptionHandler) {
return startNewBackgroundThread(
name,
MessageQueueThreadSpec.DEFAULT_STACK_SIZE_BYTES,
exceptionHandler);
}
public static MessageQueueThreadImpl startNewBackgroundThread(
final String name,
long stackSize,
QueueThreadExceptionHandler exceptionHandler) {
return startNewBackgroundThread(name, stackSize, exceptionHandler, false);
}
/**
* Creates and starts a new MessageQueueThreadImpl encapsulating a new Thread with a new Looper
* running on it. Give it a name for easier debugging and optionally a suggested stack size.
@@ -208,17 +183,14 @@ public static MessageQueueThreadImpl startNewBackgroundThread(
private static MessageQueueThreadImpl startNewBackgroundThread(
final String name,
long stackSize,
QueueThreadExceptionHandler exceptionHandler,
final boolean forUIManagerModule) {
QueueThreadExceptionHandler exceptionHandler) {
final SimpleSettableFuture<Looper> looperFuture = new SimpleSettableFuture<>();
final SimpleSettableFuture<MessageQueueThread> mqtFuture = new SimpleSettableFuture<>();
Thread bgThread = new Thread(null,
new Runnable() {
@Override
public void run() {
Process.setThreadPriority(forUIManagerModule ?
Process.THREAD_PRIORITY_DEFAULT + Process.THREAD_PRIORITY_MORE_FAVORABLE :
Process.THREAD_PRIORITY_DEFAULT);
Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
Looper.prepare();
looperFuture.set(Looper.myLooper());
@@ -22,12 +22,11 @@
protected static enum ThreadType {
MAIN_UI,
BACKGROUND_UI,
NEW_BACKGROUND,
}
public static MessageQueueThreadSpec newUIBackgroundTreadSpec(String name) {
return new MessageQueueThreadSpec(ThreadType.BACKGROUND_UI, name);
return new MessageQueueThreadSpec(ThreadType.NEW_BACKGROUND, name);
}
public static MessageQueueThreadSpec newBackgroundThreadSpec(String name) {

1 comment on commit 82c4b9f

@henrikra

This comment has been minimized.

Show comment
Hide comment
@henrikra

henrikra Jun 8, 2017

Does this mean the app will start faster or?

Does this mean the app will start faster or?

Please sign in to comment.