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.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ public class MessageQueueThreadSpec {

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) {
Expand Down

0 comments on commit 82c4b9f

Please sign in to comment.