Pass minTimeLeftInFrameForNonBatchedOperationMs from above

Reviewed By: AaaChiuuu

Differential Revision: D5658066

fbshipit-source-id: f89a8bcfc180210f7361b03f718f65b1d59cbf85
This commit is contained in:
Alexey Lang
2017-08-20 17:23:50 -07:00
committed by Facebook Github Bot
parent a777517651
commit 992777b765
23 changed files with 268 additions and 296 deletions

View File

@@ -9,10 +9,10 @@
package com.facebook.react;
import javax.inject.Provider;
import java.util.ArrayList;
import java.util.List;
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_END;
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_START;
import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_END;
import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_START;
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.NativeModule;
@@ -36,11 +36,9 @@ import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.systrace.Systrace;
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_END;
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_START;
import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_END;
import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_START;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Provider;
/**
* This module should be removed following the completion of an experiment into splitting this into
* three modules to allow for more light-weight instantiations of the bridge without UIManager
@@ -74,16 +72,19 @@ import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_
private final DefaultHardwareBackBtnHandler mHardwareBackBtnHandler;
private final UIImplementationProvider mUIImplementationProvider;
private final boolean mLazyViewManagersEnabled;
private final int mMinTimeLeftInFrameForNonBatchedOperationMs;
CoreModulesPackage(
ReactInstanceManager reactInstanceManager,
DefaultHardwareBackBtnHandler hardwareBackBtnHandler,
UIImplementationProvider uiImplementationProvider,
boolean lazyViewManagersEnabled) {
ReactInstanceManager reactInstanceManager,
DefaultHardwareBackBtnHandler hardwareBackBtnHandler,
UIImplementationProvider uiImplementationProvider,
boolean lazyViewManagersEnabled,
int minTimeLeftInFrameForNonBatchedOperationMs) {
mReactInstanceManager = reactInstanceManager;
mHardwareBackBtnHandler = hardwareBackBtnHandler;
mUIImplementationProvider = uiImplementationProvider;
mLazyViewManagersEnabled = lazyViewManagersEnabled;
mMinTimeLeftInFrameForNonBatchedOperationMs = minTimeLeftInFrameForNonBatchedOperationMs;
}
@Override
@@ -189,10 +190,11 @@ import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_
List<ViewManager> viewManagersList = mReactInstanceManager.createAllViewManagers(
reactContext);
return new UIManagerModule(
reactContext,
viewManagersList,
mUIImplementationProvider,
mLazyViewManagersEnabled);
reactContext,
viewManagersList,
mUIImplementationProvider,
mLazyViewManagersEnabled,
mMinTimeLeftInFrameForNonBatchedOperationMs);
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END);

View File

@@ -46,6 +46,7 @@ import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.bridge.JSCJavaScriptExecutor;
import com.facebook.react.bridge.JavaJSExecutor;
import com.facebook.react.bridge.JavaScriptExecutor;
import com.facebook.react.bridge.NativeArray;
import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
import com.facebook.react.bridge.NativeModuleRegistry;
import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
@@ -55,7 +56,6 @@ import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.NativeArray;
import com.facebook.react.bridge.queue.ReactQueueConfigurationSpec;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.common.ReactConstants;
@@ -149,6 +149,7 @@ public class ReactInstanceManager {
private final boolean mLazyViewManagersEnabled;
private final boolean mUseSeparateUIBackgroundThread;
private final int mMinNumShakes;
private final int mMinTimeLeftInFrameForNonBatchedOperationMs;
private final ReactInstanceDevCommandsHandler mDevInterface =
new ReactInstanceDevCommandsHandler() {
@@ -205,26 +206,27 @@ public class ReactInstanceManager {
}
/* package */ ReactInstanceManager(
Context applicationContext,
@Nullable Activity currentActivity,
@Nullable DefaultHardwareBackBtnHandler defaultHardwareBackBtnHandler,
@Nullable JSBundleLoader bundleLoader,
@Nullable String jsMainModulePath,
List<ReactPackage> packages,
boolean useDeveloperSupport,
@Nullable NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener,
LifecycleState initialLifecycleState,
UIImplementationProvider uiImplementationProvider,
NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler,
JSCConfig jscConfig,
@Nullable RedBoxHandler redBoxHandler,
boolean lazyNativeModulesEnabled,
boolean lazyViewManagersEnabled,
@Nullable DevBundleDownloadListener devBundleDownloadListener,
boolean useSeparateUIBackgroundThread,
int minNumShakes,
boolean splitPackagesEnabled,
boolean useOnlyDefaultPackages) {
Context applicationContext,
@Nullable Activity currentActivity,
@Nullable DefaultHardwareBackBtnHandler defaultHardwareBackBtnHandler,
@Nullable JSBundleLoader bundleLoader,
@Nullable String jsMainModulePath,
List<ReactPackage> packages,
boolean useDeveloperSupport,
@Nullable NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener,
LifecycleState initialLifecycleState,
UIImplementationProvider uiImplementationProvider,
NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler,
JSCConfig jscConfig,
@Nullable RedBoxHandler redBoxHandler,
boolean lazyNativeModulesEnabled,
boolean lazyViewManagersEnabled,
@Nullable DevBundleDownloadListener devBundleDownloadListener,
boolean useSeparateUIBackgroundThread,
int minNumShakes,
boolean splitPackagesEnabled,
boolean useOnlyDefaultPackages,
int minTimeLeftInFrameForNonBatchedOperationMs) {
Log.d(ReactConstants.TAG, "ReactInstanceManager.ctor()");
initializeSoLoaderIfNecessary(applicationContext);
@@ -254,16 +256,18 @@ public class ReactInstanceManager {
mJSCConfig = jscConfig;
mLazyNativeModulesEnabled = lazyNativeModulesEnabled;
mLazyViewManagersEnabled = lazyViewManagersEnabled;
mMinTimeLeftInFrameForNonBatchedOperationMs = minTimeLeftInFrameForNonBatchedOperationMs;
mUseSeparateUIBackgroundThread = useSeparateUIBackgroundThread;
mMinNumShakes = minNumShakes;
if (!splitPackagesEnabled) {
CoreModulesPackage coreModulesPackage =
new CoreModulesPackage(
this,
mBackBtnHandler,
mUIImplementationProvider,
mLazyViewManagersEnabled);
new CoreModulesPackage(
this,
mBackBtnHandler,
mUIImplementationProvider,
mLazyViewManagersEnabled,
mMinTimeLeftInFrameForNonBatchedOperationMs);
mPackages.add(coreModulesPackage);
} else {
mPackages.add(new BridgeCorePackage(this, mBackBtnHandler));
@@ -272,10 +276,11 @@ public class ReactInstanceManager {
}
if (!useOnlyDefaultPackages) {
mPackages.add(
new ReactNativeCorePackage(
this,
mUIImplementationProvider,
mLazyViewManagersEnabled));
new ReactNativeCorePackage(
this,
mUIImplementationProvider,
mLazyViewManagersEnabled,
mMinTimeLeftInFrameForNonBatchedOperationMs));
}
}
mPackages.addAll(packages);

View File

@@ -45,6 +45,7 @@ public class ReactInstanceManagerBuilder {
private int mMinNumShakes = 1;
private boolean mEnableSplitPackage;
private boolean mUseOnlyDefaultPackages;
private int mMinTimeLeftInFrameForNonBatchedOperationMs = -1;
/* package protected */ ReactInstanceManagerBuilder() {
}
@@ -216,6 +217,12 @@ public class ReactInstanceManagerBuilder {
return this;
}
public ReactInstanceManagerBuilder setMinTimeLeftInFrameForNonBatchedOperationMs(
int minTimeLeftInFrameForNonBatchedOperationMs) {
mMinTimeLeftInFrameForNonBatchedOperationMs = minTimeLeftInFrameForNonBatchedOperationMs;
return this;
}
/**
* Instantiates a new {@link ReactInstanceManager}.
* Before calling {@code build}, the following must be called:
@@ -245,27 +252,29 @@ public class ReactInstanceManagerBuilder {
}
return new ReactInstanceManager(
mApplication,
mCurrentActivity,
mDefaultHardwareBackBtnHandler,
(mJSBundleLoader == null && mJSBundleAssetUrl != null) ?
JSBundleLoader.createAssetLoader(mApplication, mJSBundleAssetUrl, false /*Asynchronous*/) :
mJSBundleLoader,
mJSMainModulePath,
mPackages,
mUseDeveloperSupport,
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider,
mNativeModuleCallExceptionHandler,
mJSCConfig,
mRedBoxHandler,
mLazyNativeModulesEnabled,
mLazyViewManagersEnabled,
mDevBundleDownloadListener,
mUseSeparateUIBackgroundThread,
mMinNumShakes,
mEnableSplitPackage,
mUseOnlyDefaultPackages);
mApplication,
mCurrentActivity,
mDefaultHardwareBackBtnHandler,
(mJSBundleLoader == null && mJSBundleAssetUrl != null)
? JSBundleLoader.createAssetLoader(
mApplication, mJSBundleAssetUrl, false /*Asynchronous*/)
: mJSBundleLoader,
mJSMainModulePath,
mPackages,
mUseDeveloperSupport,
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider,
mNativeModuleCallExceptionHandler,
mJSCConfig,
mRedBoxHandler,
mLazyNativeModulesEnabled,
mLazyViewManagersEnabled,
mDevBundleDownloadListener,
mUseSeparateUIBackgroundThread,
mMinNumShakes,
mEnableSplitPackage,
mUseOnlyDefaultPackages,
mMinTimeLeftInFrameForNonBatchedOperationMs);
}
}

View File

@@ -9,10 +9,8 @@
package com.facebook.react;
import javax.inject.Provider;
import java.util.ArrayList;
import java.util.List;
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_END;
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_START;
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.NativeModule;
@@ -24,9 +22,9 @@ import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.systrace.Systrace;
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_END;
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_START;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Provider;
/**
* Package defining core framework modules for initializing ReactNative (e.g. UIManager). It should be used for modules that
@@ -43,14 +41,17 @@ public class ReactNativeCorePackage extends LazyReactPackage {
private final ReactInstanceManager mReactInstanceManager;
private final UIImplementationProvider mUIImplementationProvider;
private final boolean mLazyViewManagersEnabled;
private final int mMinTimeLeftInFrameForNonBatchedOperationMs;
public ReactNativeCorePackage(
ReactInstanceManager reactInstanceManager,
UIImplementationProvider uiImplementationProvider,
boolean lazyViewManagersEnabled) {
ReactInstanceManager reactInstanceManager,
UIImplementationProvider uiImplementationProvider,
boolean lazyViewManagersEnabled,
int minTimeLeftInFrameForNonBatchedOperationMs) {
mReactInstanceManager = reactInstanceManager;
mUIImplementationProvider = uiImplementationProvider;
mLazyViewManagersEnabled = lazyViewManagersEnabled;
mMinTimeLeftInFrameForNonBatchedOperationMs = minTimeLeftInFrameForNonBatchedOperationMs;
}
@Override
@@ -83,10 +84,11 @@ public class ReactNativeCorePackage extends LazyReactPackage {
List<ViewManager> viewManagersList = mReactInstanceManager.createAllViewManagers(
reactContext);
return new UIManagerModule(
reactContext,
viewManagersList,
mUIImplementationProvider,
mLazyViewManagersEnabled);
reactContext,
viewManagersList,
mUIImplementationProvider,
mLazyViewManagersEnabled,
mMinTimeLeftInFrameForNonBatchedOperationMs);
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END);

View File

@@ -22,12 +22,11 @@ import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.uimanager.ViewManagerRegistry;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.yoga.YogaDirection;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
/**
* FlatUIImplementation builds on top of UIImplementation and allows pre-creating everything
@@ -88,7 +87,8 @@ public class FlatUIImplementation extends UIImplementation {
ReactApplicationContext reactContext,
List<ViewManager> viewManagers,
EventDispatcher eventDispatcher,
boolean memoryImprovementEnabled) {
boolean memoryImprovementEnabled,
int minTimeLeftInFrameForNonBatchedOperationMs) {
Map<String, ViewManager> viewManagerMap = buildViewManagerMap(viewManagers);
@@ -107,9 +107,9 @@ public class FlatUIImplementation extends UIImplementation {
ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry(viewManagerMap);
FlatNativeViewHierarchyManager nativeViewHierarchyManager = new FlatNativeViewHierarchyManager(
viewManagerRegistry);
FlatUIViewOperationQueue operationsQueue = new FlatUIViewOperationQueue(
reactContext,
nativeViewHierarchyManager);
FlatUIViewOperationQueue operationsQueue =
new FlatUIViewOperationQueue(
reactContext, nativeViewHierarchyManager, minTimeLeftInFrameForNonBatchedOperationMs);
return new FlatUIImplementation(
reactContext,
imageViewManager,

View File

@@ -9,12 +9,11 @@
package com.facebook.react.flat;
import java.util.List;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.uimanager.events.EventDispatcher;
import java.util.List;
/**
* UIImplementationProvider that creates instances of {@link FlatUIImplementation}.
@@ -35,11 +34,13 @@ public final class FlatUIImplementationProvider extends UIImplementationProvider
public FlatUIImplementation createUIImplementation(
ReactApplicationContext reactContext,
List<ViewManager> viewManagers,
EventDispatcher eventDispatcher) {
EventDispatcher eventDispatcher,
int minTimeLeftInFrameForNonBatchedOperationMs) {
return FlatUIImplementation.createInstance(
reactContext,
viewManagers,
eventDispatcher,
mMemoryImprovementEnabled);
reactContext,
viewManagers,
eventDispatcher,
mMemoryImprovementEnabled,
minTimeLeftInFrameForNonBatchedOperationMs);
}
}

View File

@@ -9,14 +9,9 @@
package com.facebook.react.flat;
import javax.annotation.Nullable;
import java.util.ArrayList;
import android.util.SparseIntArray;
import android.view.View;
import android.view.ViewGroup;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableArray;
@@ -25,6 +20,8 @@ import com.facebook.react.uimanager.NoSuchNativeViewException;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.TouchTargetHelper;
import com.facebook.react.uimanager.UIViewOperationQueue;
import java.util.ArrayList;
import javax.annotation.Nullable;
/**
* FlatUIViewOperationQueue extends {@link UIViewOperationQueue} to add
@@ -399,8 +396,9 @@ import com.facebook.react.uimanager.UIViewOperationQueue;
public FlatUIViewOperationQueue(
ReactApplicationContext reactContext,
FlatNativeViewHierarchyManager nativeViewHierarchyManager) {
super(reactContext, nativeViewHierarchyManager);
FlatNativeViewHierarchyManager nativeViewHierarchyManager,
int minTimeLeftInFrameForNonBatchedOperationMs) {
super(reactContext, nativeViewHierarchyManager, minTimeLeftInFrameForNonBatchedOperationMs);
mNativeViewHierarchyManager = nativeViewHierarchyManager;
}

View File

@@ -48,20 +48,29 @@ public class UIImplementation {
private long mLastCalculateLayoutTime = 0;
public UIImplementation(
ReactApplicationContext reactContext,
List<ViewManager> viewManagers,
EventDispatcher eventDispatcher) {
this(reactContext, new ViewManagerRegistry(viewManagers), eventDispatcher);
ReactApplicationContext reactContext,
List<ViewManager> viewManagers,
EventDispatcher eventDispatcher,
int minTimeLeftInFrameForNonBatchedOperationMs) {
this(
reactContext,
new ViewManagerRegistry(viewManagers),
eventDispatcher,
minTimeLeftInFrameForNonBatchedOperationMs);
}
private UIImplementation(
ReactApplicationContext reactContext,
ViewManagerRegistry viewManagers,
EventDispatcher eventDispatcher) {
ReactApplicationContext reactContext,
ViewManagerRegistry viewManagers,
EventDispatcher eventDispatcher,
int minTimeLeftInFrameForNonBatchedOperationMs) {
this(
reactContext,
viewManagers,
new UIViewOperationQueue(reactContext, new NativeViewHierarchyManager(viewManagers)),
new UIViewOperationQueue(
reactContext,
new NativeViewHierarchyManager(viewManagers),
minTimeLeftInFrameForNonBatchedOperationMs),
eventDispatcher);
}

View File

@@ -8,10 +8,9 @@
*/
package com.facebook.react.uimanager;
import java.util.List;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.events.EventDispatcher;
import java.util.List;
/**
* Provides UIImplementation to use in {@link UIManagerModule}.
@@ -20,7 +19,9 @@ public class UIImplementationProvider {
public UIImplementation createUIImplementation(
ReactApplicationContext reactContext,
List<ViewManager> viewManagers,
EventDispatcher eventDispatcher) {
return new UIImplementation(reactContext, viewManagers, eventDispatcher);
EventDispatcher eventDispatcher,
int minTimeLeftInFrameForNonBatchedOperationMs) {
return new UIImplementation(
reactContext, viewManagers, eventDispatcher, minTimeLeftInFrameForNonBatchedOperationMs);
}
}

View File

@@ -85,13 +85,18 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
ReactApplicationContext reactContext,
List<ViewManager> viewManagerList,
UIImplementationProvider uiImplementationProvider,
boolean lazyViewManagersEnabled) {
boolean lazyViewManagersEnabled,
int minTimeLeftInFrameForNonBatchedOperationMs) {
super(reactContext);
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
mEventDispatcher = new EventDispatcher(reactContext);
mModuleConstants = createConstants(viewManagerList, lazyViewManagersEnabled);
mUIImplementation = uiImplementationProvider
.createUIImplementation(reactContext, viewManagerList, mEventDispatcher);
mUIImplementation =
uiImplementationProvider.createUIImplementation(
reactContext,
viewManagerList,
mEventDispatcher,
minTimeLeftInFrameForNonBatchedOperationMs);
reactContext.addLifecycleEventListener(this);
}

View File

@@ -46,6 +46,8 @@ import javax.annotation.concurrent.GuardedBy;
*/
public class UIViewOperationQueue {
public static final int DEFAULT_MIN_TIME_LEFT_IN_FRAME_FOR_NONBATCHED_OPERATION_MS = 8;
private final int[] mMeasureBuffer = new int[4];
/**
@@ -554,10 +556,16 @@ public class UIViewOperationQueue {
public UIViewOperationQueue(
ReactApplicationContext reactContext,
NativeViewHierarchyManager nativeViewHierarchyManager) {
NativeViewHierarchyManager nativeViewHierarchyManager,
int minTimeLeftInFrameForNonBatchedOperationMs) {
mNativeViewHierarchyManager = nativeViewHierarchyManager;
mAnimationRegistry = nativeViewHierarchyManager.getAnimationRegistry();
mDispatchUIFrameCallback = new DispatchUIFrameCallback(reactContext);
mDispatchUIFrameCallback =
new DispatchUIFrameCallback(
reactContext,
minTimeLeftInFrameForNonBatchedOperationMs == -1
? DEFAULT_MIN_TIME_LEFT_IN_FRAME_FOR_NONBATCHED_OPERATION_MS
: minTimeLeftInFrameForNonBatchedOperationMs);
mReactApplicationContext = reactContext;
}
@@ -936,11 +944,13 @@ public class UIViewOperationQueue {
*/
private class DispatchUIFrameCallback extends GuardedFrameCallback {
private static final int MIN_TIME_LEFT_IN_FRAME_TO_SCHEDULE_MORE_WORK_MS = 8;
private static final int FRAME_TIME_MS = 16;
private final int mMinTimeLeftInFrameForNonBatchedOperationMs;
private DispatchUIFrameCallback(ReactContext reactContext) {
private DispatchUIFrameCallback(
ReactContext reactContext, int minTimeLeftInFrameForNonBatchedOperationMs) {
super(reactContext);
mMinTimeLeftInFrameForNonBatchedOperationMs = minTimeLeftInFrameForNonBatchedOperationMs;
}
@Override
@@ -984,7 +994,7 @@ public class UIViewOperationQueue {
private void dispatchPendingNonBatchedOperations(long frameTimeNanos) {
while (true) {
long timeLeftInFrame = FRAME_TIME_MS - ((System.nanoTime() - frameTimeNanos) / 1000000);
if (timeLeftInFrame < MIN_TIME_LEFT_IN_FRAME_TO_SCHEDULE_MORE_WORK_MS) {
if (timeLeftInFrame < mMinTimeLeftInFrameForNonBatchedOperationMs) {
break;
}