mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-10 22:47:58 +08:00
bump up priority of RN threads during startup
Reviewed By: shergin, yungsters Differential Revision: D5002320 fbshipit-source-id: 8467370940d3742266b3bf319e9a38ae22eab98e
This commit is contained in:
committed by
Facebook Github Bot
parent
1dd7bc1515
commit
82c4b9f0b7
@@ -742,7 +742,7 @@ public class ReactInstanceManager {
|
||||
@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 @@ public class ReactInstanceManager {
|
||||
}
|
||||
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 class MessageQueueThreadImpl implements MessageQueueThread {
|
||||
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 class MessageQueueThreadImpl implements MessageQueueThread {
|
||||
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 class MessageQueueThreadImpl implements MessageQueueThread {
|
||||
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 @@ 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) {
|
||||
|
||||
Reference in New Issue
Block a user