Skip to content

Commit

Permalink
Ship lockfree mountitems
Browse files Browse the repository at this point in the history
Summary:
Ship lockfree mountitems experiment.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D25775521

fbshipit-source-id: 15811b15a9dc7d463a6d46d7fefd0d433ba86280
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Jan 5, 2021
1 parent 934275f commit a2164f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ public class ReactFeatureFlags {
/** Feature flag to configure eager initialization of Fabric */
public static boolean eagerInitializeFabric = false;

/** Use lock-free data structures for Fabric MountItems. */
public static boolean enableLockFreeMountInstructions = false;

/** Disable UI update operations in non-Fabric renderer after catalyst instance was destroyed */
public static boolean disableNonFabricViewOperationsOnCatalystDestroy = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.os.SystemClock;
import android.view.View;
import androidx.annotation.AnyThread;
import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
Expand Down Expand Up @@ -87,7 +86,6 @@
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.views.text.TextLayoutManager;
import com.facebook.systrace.Systrace;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -133,7 +131,6 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
@NonNull
private final CopyOnWriteArrayList<UIManagerListener> mListeners = new CopyOnWriteArrayList<>();

// Concurrent MountItem data-structures, experimental. TODO: T79662803
@NonNull
private final ConcurrentLinkedQueue<DispatchCommandMountItem> mViewCommandMountItemsConcurrent =
new ConcurrentLinkedQueue<>();
Expand All @@ -146,24 +143,6 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
private final ConcurrentLinkedQueue<PreAllocateViewMountItem> mPreMountItemsConcurrent =
new ConcurrentLinkedQueue<>();

// Non-concurrent MountItem data-structures
@NonNull private final Object mViewCommandMountItemsLock = new Object();
@NonNull private final Object mMountItemsLock = new Object();
@NonNull private final Object mPreMountItemsLock = new Object();

@GuardedBy("mViewCommandMountItemsLock")
@NonNull
private List<DispatchCommandMountItem> mViewCommandMountItems = new ArrayList<>();

@GuardedBy("mMountItemsLock")
@NonNull
private List<MountItem> mMountItems = new ArrayList<>();

@GuardedBy("mPreMountItemsLock")
@NonNull
private ArrayDeque<PreAllocateViewMountItem> mPreMountItems =
new ArrayDeque<>(PRE_MOUNT_ITEMS_INITIAL_SIZE_ARRAY);

@ThreadConfined(UI)
@NonNull
private final DispatchUIFrameCallback mDispatchUIFrameCallback;
Expand Down Expand Up @@ -807,50 +786,17 @@ private <E extends MountItem> List<E> drainConcurrentItemQueue(ConcurrentLinkedQ
@UiThread
@ThreadConfined(UI)
private List<DispatchCommandMountItem> getAndResetViewCommandMountItems() {
if (ReactFeatureFlags.enableLockFreeMountInstructions) {
return drainConcurrentItemQueue(mViewCommandMountItemsConcurrent);
}

synchronized (mViewCommandMountItemsLock) {
List<DispatchCommandMountItem> result = mViewCommandMountItems;
if (result.isEmpty()) {
return null;
}
mViewCommandMountItems = new ArrayList<>();
return result;
}
return drainConcurrentItemQueue(mViewCommandMountItemsConcurrent);
}

@UiThread
@ThreadConfined(UI)
private List<MountItem> getAndResetMountItems() {
if (ReactFeatureFlags.enableLockFreeMountInstructions) {
return drainConcurrentItemQueue(mMountItemsConcurrent);
}

synchronized (mMountItemsLock) {
List<MountItem> result = mMountItems;
if (result.isEmpty()) {
return null;
}
mMountItems = new ArrayList<>();
return result;
}
return drainConcurrentItemQueue(mMountItemsConcurrent);
}

private Collection<PreAllocateViewMountItem> getAndResetPreMountItems() {
if (ReactFeatureFlags.enableLockFreeMountInstructions) {
return drainConcurrentItemQueue(mPreMountItemsConcurrent);
}

synchronized (mPreMountItemsLock) {
ArrayDeque<PreAllocateViewMountItem> result = mPreMountItems;
if (result.isEmpty()) {
return null;
}
mPreMountItems = new ArrayDeque<>(PRE_MOUNT_ITEMS_INITIAL_SIZE_ARRAY);
return result;
}
return drainConcurrentItemQueue(mPreMountItemsConcurrent);
}

/**
Expand Down Expand Up @@ -1051,16 +997,8 @@ private void dispatchPreMountItems(long frameTimeNanos) {
break;
}

PreAllocateViewMountItem preMountItemToDispatch = null;
if (ReactFeatureFlags.enableLockFreeMountInstructions) {
preMountItemToDispatch = mPreMountItemsConcurrent.poll();
} else {
synchronized (mPreMountItemsLock) {
if (!mPreMountItems.isEmpty()) {
preMountItemToDispatch = mPreMountItems.pollFirst();
}
}
}
PreAllocateViewMountItem preMountItemToDispatch = mPreMountItemsConcurrent.poll();

// If list is empty, `poll` will return null, or var will never be set
if (preMountItemToDispatch == null) {
break;
Expand Down Expand Up @@ -1268,13 +1206,7 @@ public Map<String, Long> getPerformanceCounters() {
* @param mountItem
*/
private void addMountItem(MountItem mountItem) {
if (ReactFeatureFlags.enableLockFreeMountInstructions) {
mMountItemsConcurrent.add(mountItem);
} else {
synchronized (mMountItemsLock) {
mMountItems.add(mountItem);
}
}
mMountItemsConcurrent.add(mountItem);
}

/**
Expand All @@ -1283,13 +1215,7 @@ private void addMountItem(MountItem mountItem) {
* @param mountItem
*/
private void addPreAllocateMountItem(PreAllocateViewMountItem mountItem) {
if (ReactFeatureFlags.enableLockFreeMountInstructions) {
mPreMountItemsConcurrent.add(mountItem);
} else {
synchronized (mPreMountItemsLock) {
mPreMountItems.add(mountItem);
}
}
mPreMountItemsConcurrent.add(mountItem);
}

/**
Expand All @@ -1298,13 +1224,7 @@ private void addPreAllocateMountItem(PreAllocateViewMountItem mountItem) {
* @param mountItem
*/
private void addViewCommandMountItem(DispatchCommandMountItem mountItem) {
if (ReactFeatureFlags.enableLockFreeMountInstructions) {
mViewCommandMountItemsConcurrent.add(mountItem);
} else {
synchronized (mViewCommandMountItemsLock) {
mViewCommandMountItems.add(mountItem);
}
}
mViewCommandMountItemsConcurrent.add(mountItem);
}

private class DispatchUIFrameCallback extends GuardedFrameCallback {
Expand Down

0 comments on commit a2164f4

Please sign in to comment.