Skip to content

Commit

Permalink
Remove eager view manager preinit support
Browse files Browse the repository at this point in the history
Summary:
Pre-initializing ViewManagers is not as valuable now that we've rolled out StaticViewConfigs on the new architecture. This was primarily used to pre-allocate constants and the `preInitializeViewManagers` was already deprecated.

Changelog: [Android][Removed] UIManager.preInitializeViewManagers

Reviewed By: rshest

Differential Revision: D43661304

fbshipit-source-id: 391c5207ec876a70ddd4bda30a58267090da3ff1
  • Loading branch information
javache authored and facebook-github-bot committed Mar 1, 2023
1 parent bc56f66 commit 848ac0c
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import com.facebook.infer.annotation.ThreadConfined;
import java.util.List;

public interface UIManager extends JSIModule, PerformanceCounter {

Expand Down Expand Up @@ -153,15 +152,4 @@ void updateRootLayoutSpecs(
@Deprecated
@Nullable
String resolveCustomDirectEventName(@Nullable String eventName);

/**
* Helper method to pre-initialize view managers. When using Native ViewConfigs this method will
* also pre-compute the constants for a view manager. The purpose is to ensure that we don't block
* for getting the constants for view managers during initial rendering of a surface.
*
* @deprecated this method will be removed in the future
* @param viewManagerNames {@link List <String>} names of ViewManagers
*/
@Deprecated
void preInitializeViewManagers(List<String> viewManagerNames);
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
import com.facebook.react.views.text.TextLayoutManager;
import com.facebook.react.views.text.TextLayoutManagerMapBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -276,13 +275,6 @@ public ReadableMap getInspectorDataForInstance(final int surfaceId, final View v
return mBinding.getInspectorDataForInstance(eventEmitter);
}

@Override
public void preInitializeViewManagers(List<String> viewManagerNames) {
for (String viewManagerName : viewManagerNames) {
mMountingManager.initializeViewManager(viewManagerName);
}
}

@Override
@AnyThread
@ThreadConfined(ANY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,6 @@ public long measureMapBuffer(
attachmentsPositions);
}

public void initializeViewManager(String componentName) {
mViewManagerRegistry.get(componentName);
}

public void enqueuePendingEvent(int reactTag, ViewEvent viewEvent) {
@Nullable SurfaceMountingManager smm = getSurfaceManagerForView(reactTag);
if (smm == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.ArrayMap;
import com.facebook.common.logging.FLog;
import com.facebook.debug.holder.PrinterHolder;
import com.facebook.debug.tags.ReactDebugOverlayTags;
Expand Down Expand Up @@ -49,7 +48,6 @@
import com.facebook.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -109,8 +107,6 @@ public interface CustomEventNamesResolver {
private final List<UIManagerModuleListener> mListeners = new ArrayList<>();
private final CopyOnWriteArrayList<UIManagerListener> mUIManagerListeners =
new CopyOnWriteArrayList<>();
private @Nullable Map<String, WritableMap> mViewManagerConstantsCache;
private volatile int mViewManagerConstantsCacheSize;

private int mBatchId = 0;

Expand Down Expand Up @@ -250,50 +246,8 @@ private static Map<String, Object> createConstants(
}
}

/**
* Helper method to pre-compute the constants for a view manager. This method ensures that we
* don't block for getting the constants for view managers during TTI
*
* @deprecated this method will be removed in the future
* @param viewManagerNames {@link List<String>} names of ViewManagers
*/
@Deprecated
@Override
public void preInitializeViewManagers(List<String> viewManagerNames) {
Map<String, WritableMap> constantsMap = new ArrayMap<>();
for (String viewManagerName : viewManagerNames) {
WritableMap constants = computeConstantsForViewManager(viewManagerName);
if (constants != null) {
constantsMap.put(viewManagerName, constants);
}
}

// To ensure that this is thread safe, we return an unmodifiableMap
// We use mViewManagerConstantsCacheSize to count the times we access the contents of the map
// Once we have accessed all the values, we free this cache
// Assumption is that JS gets the constants only once for each viewManager.
// Using this mechanism prevents expensive synchronized blocks, due to the nature of how this is
// accessed - write one, read multiple times, and then throw the data away.
mViewManagerConstantsCacheSize = viewManagerNames.size();
mViewManagerConstantsCache = Collections.unmodifiableMap(constantsMap);
}

@ReactMethod(isBlockingSynchronousMethod = true)
public @Nullable WritableMap getConstantsForViewManager(@Nullable String viewManagerName) {
if (mViewManagerConstantsCache != null
&& mViewManagerConstantsCache.containsKey(viewManagerName)) {
WritableMap constants = mViewManagerConstantsCache.get(viewManagerName);
if (--mViewManagerConstantsCacheSize <= 0) {
// Looks like we have read all the values from the cache, so we may as well free this cache
mViewManagerConstantsCache = null;
}
return constants;
} else {
return computeConstantsForViewManager(viewManagerName);
}
}

private @Nullable WritableMap computeConstantsForViewManager(@Nullable String viewManagerName) {
ViewManager targetView =
viewManagerName != null ? mUIImplementation.resolveViewManager(viewManagerName) : null;
if (targetView == null) {
Expand Down

0 comments on commit 848ac0c

Please sign in to comment.