Avoid view manager class loads

Summary:
We are currently iterating through each view manager to get its class name to pass to JS. JS uses this list to define lazy property accesses for each view manager to grab the constants synchronously. This results in each view manager's class loading immediately -- causing a small perf hit.

Let's avoid this view managers list entirely. JS is able to access each view manager directly by calling getConstantsForViewManager(name)

Reviewed By: TheSavior

Differential Revision: D9930713

fbshipit-source-id: 4aa013f8398d4f51b7eef07937d2977ba1950726
This commit is contained in:
Andrew Chen (Eng) authored and Facebook Github Bot committed 2018-09-27 16:03:24 -07:00
1 parent 230b7b0e72
commit 95174d4ea8
5 files changed
+107 -5

No files matched your search

@@ -10,7 +10,7 @@ package com.facebook.react.uimanager;
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
import com.facebook.react.common.MapBuilder;
import com.facebook.systrace.Systrace;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.systrace.SystraceMessage;
import java.util.List;
import java.util.Map;
@@ -35,7 +35,10 @@ import javax.annotation.Nullable;
/* package */ static Map<String, Object> createConstants(
UIManagerModule.ViewManagerResolver resolver) {
Map<String, Object> constants = UIManagerModuleConstants.getConstants();
constants.put("ViewManagerNames", resolver.getViewManagerNames());
if (!ReactFeatureFlags.lazilyLoadViewManagers) {
constants.put("ViewManagerNames", resolver.getViewManagerNames());
}
constants.put("LazyViewManagersEnabled", true);
return constants;
}