Permalink
Browse files

Remove android_react_native_perf.use_separate_ui_bg_thread experiment.

Reviewed By: AaaChiuuu

Differential Revision: D6313250

fbshipit-source-id: 583a729a157a2053827631a43e38917753e78477
  • Loading branch information...
Dmitry Zakharov authored and facebook-github-bot committed Nov 14, 2017
1 parent 0537763 commit 4f886a29a1234c967deae2354bbc5092e0e6595e
@@ -156,7 +156,6 @@
private final @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
private final boolean mLazyNativeModulesEnabled;
private final boolean mDelayViewManagerClassLoadsEnabled;
private final boolean mUseSeparateUIBackgroundThread;
private final int mMinNumShakes;
private class ReactContextInitParams {
@@ -204,7 +203,6 @@ public static ReactInstanceManagerBuilder builder() {
boolean lazyViewManagersEnabled,
boolean delayViewManagerClassLoadsEnabled,
@Nullable DevBundleDownloadListener devBundleDownloadListener,
boolean useSeparateUIBackgroundThread,
int minNumShakes,
int minTimeLeftInFrameForNonBatchedOperationMs) {
Log.d(ReactConstants.TAG, "ReactInstanceManager.ctor()");
@@ -236,7 +234,6 @@ public static ReactInstanceManagerBuilder builder() {
mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
mLazyNativeModulesEnabled = lazyNativeModulesEnabled;
mDelayViewManagerClassLoadsEnabled = delayViewManagerClassLoadsEnabled;
mUseSeparateUIBackgroundThread = useSeparateUIBackgroundThread;
mMinNumShakes = minNumShakes;
synchronized (mPackages) {
PrinterHolder.getPrinter()
@@ -995,15 +992,6 @@ public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
}
});
if (mUseSeparateUIBackgroundThread) {
reactContext.runOnUiBackgroundQueueThread(
new Runnable() {
@Override
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
}
});
}
}
private void attachRootViewToInstance(
@@ -1080,9 +1068,7 @@ private ReactApplicationContext createReactContext(
? mNativeModuleCallExceptionHandler
: mDevSupportManager;
CatalystInstanceImpl.Builder catalystInstanceBuilder = new CatalystInstanceImpl.Builder()
.setReactQueueConfigurationSpec(mUseSeparateUIBackgroundThread ?
ReactQueueConfigurationSpec.createWithSeparateUIBackgroundThread() :
ReactQueueConfigurationSpec.createDefault())
.setReactQueueConfigurationSpec(ReactQueueConfigurationSpec.createDefault())
.setJSExecutor(jsExecutor)
.setRegistry(nativeModuleRegistry)
.setJSBundleLoader(jsBundleLoader)
@@ -46,7 +46,6 @@
private boolean mDelayViewManagerClassLoadsEnabled;
private @Nullable DevBundleDownloadListener mDevBundleDownloadListener;
private @Nullable JavaScriptExecutorFactory mJavaScriptExecutorFactory;
private boolean mUseSeparateUIBackgroundThread;
private int mMinNumShakes = 1;
private int mMinTimeLeftInFrameForNonBatchedOperationMs = -1;
@@ -214,12 +213,6 @@ public ReactInstanceManagerBuilder setDevBundleDownloadListener(
return this;
}
public ReactInstanceManagerBuilder setUseSeparateUIBackgroundThread(
boolean useSeparateUIBackgroundThread) {
mUseSeparateUIBackgroundThread = useSeparateUIBackgroundThread;
return this;
}
public ReactInstanceManagerBuilder setMinNumShakes(int minNumShakes) {
mMinNumShakes = minNumShakes;
return this;
@@ -286,7 +279,6 @@ public ReactInstanceManager build() {
mLazyViewManagersEnabled,
mDelayViewManagerClassLoadsEnabled,
mDevBundleDownloadListener,
mUseSeparateUIBackgroundThread,
mMinNumShakes,
mMinTimeLeftInFrameForNonBatchedOperationMs);
}
@@ -330,7 +330,7 @@ private void updateRootLayoutSpecs(final int widthMeasureSpec, final int heightM
}
final ReactContext reactApplicationContext = mReactInstanceManager.getCurrentReactContext();
if (reactApplicationContext != null) {
reactApplicationContext.runUIBackgroundRunnable(
reactApplicationContext.runOnNativeModulesQueueThread(
new GuardedRunnable(reactApplicationContext) {
@Override
public void runGuarded() {
@@ -83,7 +83,6 @@ public String toString() {
private final NativeModuleRegistry mNativeModuleRegistry;
private final NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
private final MessageQueueThread mNativeModulesQueueThread;
private final @Nullable MessageQueueThread mUIBackgroundQueueThread;
private boolean mInitialized = false;
private volatile boolean mAcceptCalls = false;
@@ -114,7 +113,6 @@ private CatalystInstanceImpl(
mJSBundleLoader = jsBundleLoader;
mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
mNativeModulesQueueThread = mReactQueueConfiguration.getNativeModulesQueueThread();
mUIBackgroundQueueThread = mReactQueueConfiguration.getUIBackgroundQueueThread();
mTraceListener = new JSProfilerTraceListener(this);
Log.d(ReactConstants.TAG, "Initializing React Xplat Bridge before initializeBridge");
@@ -123,7 +121,6 @@ private CatalystInstanceImpl(
jsExecutor,
mReactQueueConfiguration.getJSQueueThread(),
mNativeModulesQueueThread,
mUIBackgroundQueueThread,
mNativeModuleRegistry.getJavaModules(this),
mNativeModuleRegistry.getCxxModules());
Log.d(ReactConstants.TAG, "Initializing React Xplat Bridge after initializeBridge");
@@ -191,7 +188,6 @@ private native void initializeBridge(
JavaScriptExecutor jsExecutor,
MessageQueueThread jsQueue,
MessageQueueThread moduleQueue,
MessageQueueThread uiBackgroundQueue,
Collection<JavaModuleWrapper> javaModules,
Collection<ModuleHolder> cxxModules);
@@ -44,7 +44,6 @@
private @Nullable CatalystInstance mCatalystInstance;
private @Nullable LayoutInflater mInflater;
private @Nullable MessageQueueThread mUiMessageQueueThread;
private @Nullable MessageQueueThread mUiBackgroundMessageQueueThread;
private @Nullable MessageQueueThread mNativeModulesMessageQueueThread;
private @Nullable MessageQueueThread mJSMessageQueueThread;
private @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
@@ -69,7 +68,6 @@ public void initializeWithInstance(CatalystInstance catalystInstance) {
ReactQueueConfiguration queueConfig = catalystInstance.getReactQueueConfiguration();
mUiMessageQueueThread = queueConfig.getUIQueueThread();
mUiBackgroundMessageQueueThread = queueConfig.getUIBackgroundQueueThread();
mNativeModulesMessageQueueThread = queueConfig.getNativeModulesQueueThread();
mJSMessageQueueThread = queueConfig.getJSQueueThread();
}
@@ -269,14 +267,6 @@ public void runOnUiQueueThread(Runnable runnable) {
Assertions.assertNotNull(mUiMessageQueueThread).runOnQueue(runnable);
}
public void assertOnUiBackgroundQueueThread() {
Assertions.assertNotNull(mUiBackgroundMessageQueueThread).assertIsOnThread();
}
public void runOnUiBackgroundQueueThread(Runnable runnable) {
Assertions.assertNotNull(mUiBackgroundMessageQueueThread).runOnQueue(runnable);
}
public void assertOnNativeModulesQueueThread() {
Assertions.assertNotNull(mNativeModulesMessageQueueThread).assertIsOnThread();
}
@@ -305,26 +295,6 @@ public void runOnJSQueueThread(Runnable runnable) {
Assertions.assertNotNull(mJSMessageQueueThread).runOnQueue(runnable);
}
public boolean hasUIBackgroundRunnableThread() {
return mUiBackgroundMessageQueueThread != null;
}
public void assertOnUIBackgroundOrNativeModulesThread() {
if (mUiBackgroundMessageQueueThread == null) {
assertOnNativeModulesQueueThread();
} else {
assertOnUiBackgroundQueueThread();
}
}
public void runUIBackgroundRunnable(Runnable runnable) {
if (mUiBackgroundMessageQueueThread == null) {
runOnNativeModulesQueueThread(runnable);
} else {
runOnUiBackgroundQueueThread(runnable);
}
}
/**
* Passes the given exception to the current
* {@link com.facebook.react.bridge.NativeModuleCallExceptionHandler} if one exists, rethrowing
@@ -9,7 +9,6 @@
package com.facebook.react.bridge.queue;
import javax.annotation.Nullable;
/**
* Specifies which {@link MessageQueueThread}s must be used to run the various contexts of
@@ -22,8 +21,6 @@
*/
public interface ReactQueueConfiguration {
MessageQueueThread getUIQueueThread();
@Nullable
MessageQueueThread getUIBackgroundQueueThread();
MessageQueueThread getNativeModulesQueueThread();
MessageQueueThread getJSQueueThread();
void destroy();
@@ -9,8 +9,6 @@
package com.facebook.react.bridge.queue;
import javax.annotation.Nullable;
import java.util.Map;
import android.os.Looper;
@@ -20,17 +18,14 @@
public class ReactQueueConfigurationImpl implements ReactQueueConfiguration {
private final MessageQueueThreadImpl mUIQueueThread;
private final @Nullable MessageQueueThreadImpl mUIBackgroundQueueThread;
private final MessageQueueThreadImpl mNativeModulesQueueThread;
private final MessageQueueThreadImpl mJSQueueThread;
private ReactQueueConfigurationImpl(
MessageQueueThreadImpl uiQueueThread,
@Nullable MessageQueueThreadImpl uiBackgroundQueueThread,
MessageQueueThreadImpl nativeModulesQueueThread,
MessageQueueThreadImpl jsQueueThread) {
MessageQueueThreadImpl uiQueueThread,
MessageQueueThreadImpl nativeModulesQueueThread,
MessageQueueThreadImpl jsQueueThread) {
mUIQueueThread = uiQueueThread;
mUIBackgroundQueueThread = uiBackgroundQueueThread;
mNativeModulesQueueThread = nativeModulesQueueThread;
mJSQueueThread = jsQueueThread;
}
@@ -40,11 +35,6 @@ public MessageQueueThread getUIQueueThread() {
return mUIQueueThread;
}
@Override
public @Nullable MessageQueueThread getUIBackgroundQueueThread() {
return mUIBackgroundQueueThread;
}
@Override
public MessageQueueThread getNativeModulesQueueThread() {
return mNativeModulesQueueThread;
@@ -60,10 +50,6 @@ public MessageQueueThread getJSQueueThread() {
* is destroyed so that we shut down the proper queue threads.
*/
public void destroy() {
if (mUIBackgroundQueueThread != null &&
mUIBackgroundQueueThread.getLooper() != Looper.getMainLooper()) {
mUIBackgroundQueueThread.quitSynchronous();
}
if (mNativeModulesQueueThread.getLooper() != Looper.getMainLooper()) {
mNativeModulesQueueThread.quitSynchronous();
}
@@ -94,16 +80,8 @@ public static ReactQueueConfigurationImpl create(
MessageQueueThreadImpl.create(spec.getNativeModulesQueueThreadSpec(), exceptionHandler);
}
MessageQueueThreadImpl uiBackgroundThread =
specsToThreads.get(spec.getUIBackgroundQueueThreadSpec());
if (uiBackgroundThread == null && spec.getUIBackgroundQueueThreadSpec() != null) {
uiBackgroundThread =
MessageQueueThreadImpl.create(spec.getUIBackgroundQueueThreadSpec(), exceptionHandler);
}
return new ReactQueueConfigurationImpl(
uiThread,
uiBackgroundThread,
nativeModulesThread,
jsThread);
}
@@ -25,23 +25,16 @@
private static final long LEGACY_STACK_SIZE_BYTES = 2000000;
private final @Nullable MessageQueueThreadSpec mUIBackgroundQueueThreadSpec;
private final MessageQueueThreadSpec mNativeModulesQueueThreadSpec;
private final MessageQueueThreadSpec mJSQueueThreadSpec;
private ReactQueueConfigurationSpec(
@Nullable MessageQueueThreadSpec uiBackgroundQueueThreadSpec,
MessageQueueThreadSpec nativeModulesQueueThreadSpec,
MessageQueueThreadSpec jsQueueThreadSpec) {
mUIBackgroundQueueThreadSpec = uiBackgroundQueueThreadSpec;
mNativeModulesQueueThreadSpec = nativeModulesQueueThreadSpec;
mJSQueueThreadSpec = jsQueueThreadSpec;
}
public @Nullable MessageQueueThreadSpec getUIBackgroundQueueThreadSpec() {
return mUIBackgroundQueueThreadSpec;
}
public MessageQueueThreadSpec getNativeModulesQueueThreadSpec() {
return mNativeModulesQueueThreadSpec;
}
@@ -64,32 +57,11 @@ public static ReactQueueConfigurationSpec createDefault() {
.build();
}
public static ReactQueueConfigurationSpec createWithSeparateUIBackgroundThread() {
MessageQueueThreadSpec spec = Build.VERSION.SDK_INT < 21 ?
MessageQueueThreadSpec.newBackgroundThreadSpec("native_modules", LEGACY_STACK_SIZE_BYTES) :
MessageQueueThreadSpec.newBackgroundThreadSpec("native_modules");
return builder()
.setJSQueueThreadSpec(MessageQueueThreadSpec.newBackgroundThreadSpec("js"))
.setNativeModulesQueueThreadSpec(spec)
.setUIBackgroundQueueThreadSpec(
MessageQueueThreadSpec.newUIBackgroundTreadSpec("ui_background"))
.build();
}
public static class Builder {
private @Nullable MessageQueueThreadSpec mUIBackgroundQueueSpec;
private @Nullable MessageQueueThreadSpec mNativeModulesQueueSpec;
private @Nullable MessageQueueThreadSpec mJSQueueSpec;
public Builder setUIBackgroundQueueThreadSpec(MessageQueueThreadSpec spec) {
Assertions.assertCondition(
mUIBackgroundQueueSpec == null,
"Setting UI background queue multiple times!");
mUIBackgroundQueueSpec = spec;
return this;
}
public Builder setNativeModulesQueueThreadSpec(MessageQueueThreadSpec spec) {
Assertions.assertCondition(
mNativeModulesQueueSpec == null,
@@ -106,7 +78,6 @@ public Builder setJSQueueThreadSpec(MessageQueueThreadSpec spec) {
public ReactQueueConfigurationSpec build() {
return new ReactQueueConfigurationSpec(
mUIBackgroundQueueSpec,
Assertions.assertNotNull(mNativeModulesQueueSpec),
Assertions.assertNotNull(mJSQueueSpec));
}
@@ -305,7 +305,7 @@ public CustomEventNamesResolver getDirectEventNamesResolver() {
new SizeMonitoringFrameLayout.OnSizeChangedListener() {
@Override
public void onSizeChanged(final int width, final int height, int oldW, int oldH) {
reactApplicationContext.runUIBackgroundRunnable(
reactApplicationContext.runOnNativeModulesQueueThread(
new GuardedRunnable(reactApplicationContext) {
@Override
public void runGuarded() {
@@ -325,7 +325,7 @@ public void removeRootView(int rootViewTag) {
}
public void updateNodeSize(int nodeViewTag, int newWidth, int newHeight) {
getReactApplicationContext().assertOnUIBackgroundOrNativeModulesThread();
getReactApplicationContext().assertOnNativeModulesQueueThread();
mUIImplementation.updateNodeSize(nodeViewTag, newWidth, newHeight);
}
@@ -344,7 +344,7 @@ public void setViewLocalData(final int tag, final Object data) {
reactApplicationContext.assertOnUiQueueThread();
reactApplicationContext.runUIBackgroundRunnable(
reactApplicationContext.runOnNativeModulesQueueThread(
new GuardedRunnable(reactApplicationContext) {
@Override
public void runGuarded() {
@@ -306,7 +306,7 @@ protected void onSizeChanged(final int w, final int h, int oldw, int oldh) {
if (getChildCount() > 0) {
final int viewTag = getChildAt(0).getId();
ReactContext reactContext = (ReactContext) getContext();
reactContext.runUIBackgroundRunnable(
reactContext.runOnNativeModulesQueueThread(
new GuardedRunnable(reactContext) {
@Override
public void runGuarded() {
Oops, something went wrong.

2 comments on commit 4f886a2

@Hao3o5

This comment has been minimized.

Hao3o5 replied Nov 28, 2017

@DmitrySoshnikov @mojodna @facebook-github-bot What is the meaning of introducing uiBackgroundThread and why remove it now ? Thanks a lot !

@hey99xx

This comment has been minimized.

hey99xx replied Dec 6, 2017

@Hao3o5 I asked the same in #16825

Please sign in to comment.