Skip to content

Commit

Permalink
Remove android_react_native_perf.use_separate_ui_bg_thread experiment.
Browse files Browse the repository at this point in the history
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 4f886a2
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public interface ReactInstanceEventListener {
private final @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
private final boolean mLazyNativeModulesEnabled;
private final boolean mDelayViewManagerClassLoadsEnabled;
private final boolean mUseSeparateUIBackgroundThread;
private final int mMinNumShakes;

private class ReactContextInitParams {
Expand Down Expand Up @@ -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()");
Expand Down Expand Up @@ -236,7 +234,6 @@ public static ReactInstanceManagerBuilder builder() {
mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
mLazyNativeModulesEnabled = lazyNativeModulesEnabled;
mDelayViewManagerClassLoadsEnabled = delayViewManagerClassLoadsEnabled;
mUseSeparateUIBackgroundThread = useSeparateUIBackgroundThread;
mMinNumShakes = minNumShakes;
synchronized (mPackages) {
PrinterHolder.getPrinter()
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class ReactInstanceManagerBuilder {
private boolean mDelayViewManagerClassLoadsEnabled;
private @Nullable DevBundleDownloadListener mDevBundleDownloadListener;
private @Nullable JavaScriptExecutorFactory mJavaScriptExecutorFactory;
private boolean mUseSeparateUIBackgroundThread;
private int mMinNumShakes = 1;
private int mMinTimeLeftInFrameForNonBatchedOperationMs = -1;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -286,7 +279,6 @@ public ReactInstanceManager build() {
mLazyViewManagersEnabled,
mDelayViewManagerClassLoadsEnabled,
mDevBundleDownloadListener,
mUseSeparateUIBackgroundThread,
mMinNumShakes,
mMinTimeLeftInFrameForNonBatchedOperationMs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -191,7 +188,6 @@ private native void initializeBridge(
JavaScriptExecutor jsExecutor,
MessageQueueThread jsQueue,
MessageQueueThread moduleQueue,
MessageQueueThread uiBackgroundQueue,
Collection<JavaModuleWrapper> javaModules,
Collection<ModuleHolder> cxxModules);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class ReactContext extends ContextWrapper {
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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,8 +21,6 @@
*/
public interface ReactQueueConfiguration {
MessageQueueThread getUIQueueThread();
@Nullable
MessageQueueThread getUIBackgroundQueueThread();
MessageQueueThread getNativeModulesQueueThread();
MessageQueueThread getJSQueueThread();
void destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

package com.facebook.react.bridge.queue;

import javax.annotation.Nullable;

import java.util.Map;

import android.os.Looper;
Expand All @@ -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;
}
Expand All @@ -40,11 +35,6 @@ public MessageQueueThread getUIQueueThread() {
return mUIQueueThread;
}

@Override
public @Nullable MessageQueueThread getUIBackgroundQueueThread() {
return mUIBackgroundQueueThread;
}

@Override
public MessageQueueThread getNativeModulesQueueThread() {
return mNativeModulesQueueThread;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,16 @@ public class ReactQueueConfigurationSpec {

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;
}
Expand All @@ -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,
Expand All @@ -106,7 +78,6 @@ public Builder setJSQueueThreadSpec(MessageQueueThreadSpec spec) {

public ReactQueueConfigurationSpec build() {
return new ReactQueueConfigurationSpec(
mUIBackgroundQueueSpec,
Assertions.assertNotNull(mNativeModulesQueueSpec),
Assertions.assertNotNull(mJSQueueSpec));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootVi
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() {
Expand All @@ -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);
}
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading

2 comments on commit 4f886a2

@zhang-honghao
Copy link

Choose a reason for hiding this comment

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

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

@hey99xx
Copy link

@hey99xx hey99xx commented on 4f886a2 Dec 6, 2017

Choose a reason for hiding this comment

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

@Hao3o5 I asked the same in #16825

Please sign in to comment.