Skip to content

Commit

Permalink
bump up priority of RN threads during startup
Browse files Browse the repository at this point in the history
Reviewed By: shergin, yungsters

Differential Revision: D5002320

fbshipit-source-id: 8467370940d3742266b3bf319e9a38ae22eab98e
  • Loading branch information
aaronechiu authored and facebook-github-bot committed May 8, 2017
1 parent 1dd7bc1 commit 82c4b9f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 33 deletions.
Expand Up @@ -742,7 +742,7 @@ private void runCreateReactContextOnNewThread(final ReactContextInitParams initP
@Override @Override
public void run() { public void run() {
try { try {
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
final ReactApplicationContext reactApplicationContext = createReactContext( final ReactApplicationContext reactApplicationContext = createReactContext(
initParams.getJsExecutorFactory().create(), initParams.getJsExecutorFactory().create(),
initParams.getJsBundleLoader()); initParams.getJsBundleLoader());
Expand Down Expand Up @@ -827,6 +827,26 @@ private void setupReactContext(ReactApplicationContext reactContext) {
} }
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(SETUP_REACT_CONTEXT_END); 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( private void attachMeasuredRootViewToInstance(
Expand Down
Expand Up @@ -142,8 +142,6 @@ public static MessageQueueThreadImpl create(
switch (spec.getThreadType()) { switch (spec.getThreadType()) {
case MAIN_UI: case MAIN_UI:
return createForMainThread(spec.getName(), exceptionHandler); return createForMainThread(spec.getName(), exceptionHandler);
case BACKGROUND_UI:
return startUIBackgroundThread(spec.getName(), spec.getStackSize(), exceptionHandler);
case NEW_BACKGROUND: case NEW_BACKGROUND:
return startNewBackgroundThread(spec.getName(), spec.getStackSize(), exceptionHandler); return startNewBackgroundThread(spec.getName(), spec.getStackSize(), exceptionHandler);
default: default:
Expand Down Expand Up @@ -177,29 +175,6 @@ public void run() {
return mqt; 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 * 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. * running on it. Give it a name for easier debugging and optionally a suggested stack size.
Expand All @@ -208,17 +183,14 @@ public static MessageQueueThreadImpl startNewBackgroundThread(
private static MessageQueueThreadImpl startNewBackgroundThread( private static MessageQueueThreadImpl startNewBackgroundThread(
final String name, final String name,
long stackSize, long stackSize,
QueueThreadExceptionHandler exceptionHandler, QueueThreadExceptionHandler exceptionHandler) {
final boolean forUIManagerModule) {
final SimpleSettableFuture<Looper> looperFuture = new SimpleSettableFuture<>(); final SimpleSettableFuture<Looper> looperFuture = new SimpleSettableFuture<>();
final SimpleSettableFuture<MessageQueueThread> mqtFuture = new SimpleSettableFuture<>(); final SimpleSettableFuture<MessageQueueThread> mqtFuture = new SimpleSettableFuture<>();
Thread bgThread = new Thread(null, Thread bgThread = new Thread(null,
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
Process.setThreadPriority(forUIManagerModule ? Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
Process.THREAD_PRIORITY_DEFAULT + Process.THREAD_PRIORITY_MORE_FAVORABLE :
Process.THREAD_PRIORITY_DEFAULT);
Looper.prepare(); Looper.prepare();


looperFuture.set(Looper.myLooper()); looperFuture.set(Looper.myLooper());
Expand Down
Expand Up @@ -22,12 +22,11 @@ public class MessageQueueThreadSpec {


protected static enum ThreadType { protected static enum ThreadType {
MAIN_UI, MAIN_UI,
BACKGROUND_UI,
NEW_BACKGROUND, NEW_BACKGROUND,
} }


public static MessageQueueThreadSpec newUIBackgroundTreadSpec(String name) { 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) { public static MessageQueueThreadSpec newBackgroundThreadSpec(String name) {
Expand Down

1 comment on commit 82c4b9f

@henrikra
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the app will start faster or?

Please sign in to comment.