Create ReactFeatureFlag to initialize MapBufferSo file during Fabric initialization

Summary:
This diff creates a ReactFeatureFlag to initialize MapBufferSo file during Fabric initialization.

This is necessary to be able to compare properly Mapbuffer vs ReadableNativeMap (because ReadableNativeMap c++ files is already included in the bridge so file)

changelog: [internal]

Reviewed By: JoshuaGross

Differential Revision: D28436044

fbshipit-source-id: 338e1bb72b5313dc29a309e1b0e979e7c8bd1c18
This commit is contained in:
David Vacca 2021-05-14 12:53:48 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 73fbe80fc4
Коммит 0b371304aa
6 изменённых файлов: 49 добавлений и 3 удалений

Просмотреть файл

@ -119,5 +119,7 @@ public enum ReactMarkerConstants {
REACT_BRIDGE_LOADING_START,
REACT_BRIDGE_LOADING_END,
REACT_BRIDGELESS_LOADING_START,
REACT_BRIDGELESS_LOADING_END
REACT_BRIDGELESS_LOADING_END,
LOAD_REACT_NATIVE_MAPBUFFER_SO_FILE_START,
LOAD_REACT_NATIVE_MAPBUFFER_SO_FILE_END,
}

Просмотреть файл

@ -21,6 +21,9 @@ rn_android_library(
react_native_dep("third-party/android/androidx:annotation"),
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_target("java/com/facebook/react/common:common"),
# dependencies used for systraces
react_native_dep("java/com/facebook/systrace:systrace"),
react_native_target("java/com/facebook/react/bridge:bridge"),
],
exported_deps = [],
)

Просмотреть файл

@ -10,7 +10,6 @@ package com.facebook.react.common.mapbuffer;
import androidx.annotation.Nullable;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.soloader.SoLoader;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Iterator;
@ -23,7 +22,7 @@ import java.util.Iterator;
public class ReadableMapBuffer implements Iterable<ReadableMapBuffer.MapBufferEntry> {
static {
SoLoader.loadLibrary("mapbufferjni");
ReadableMapBufferSoLoader.staticInit();
}
// Value used to verify if the data is serialized with LittleEndian order.

Просмотреть файл

@ -0,0 +1,33 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.common.mapbuffer;
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.soloader.SoLoader;
import com.facebook.systrace.Systrace;
public class ReadableMapBufferSoLoader {
private static volatile boolean sDidInit = false;
public static void staticInit() {
if (sDidInit) {
return;
}
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"ReadableMapBufferSoLoader.staticInit::load:mapbufferjni");
ReactMarker.logMarker(ReactMarkerConstants.LOAD_REACT_NATIVE_MAPBUFFER_SO_FILE_START);
SoLoader.loadLibrary("mapbufferjni");
ReactMarker.logMarker(ReactMarkerConstants.LOAD_REACT_NATIVE_MAPBUFFER_SO_FILE_END);
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
sDidInit = true;
}
}

Просмотреть файл

@ -60,6 +60,9 @@ public class ReactFeatureFlags {
/** Enables JS Responder in Fabric */
public static boolean enableJSResponder = false;
/** Feature flag to configure eager initialization of MapBuffer So file */
public static boolean enableEagerInitializeMapBufferSoFile = false;
/** An interface used to compute flags on demand. */
public interface FlagProvider {
boolean get();

Просмотреть файл

@ -15,6 +15,8 @@ import com.facebook.react.bridge.JSIModuleProvider;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.bridge.queue.MessageQueueThread;
import com.facebook.react.common.mapbuffer.ReadableMapBuffer;
import com.facebook.react.common.mapbuffer.ReadableMapBufferSoLoader;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.fabric.events.EventBeatManager;
import com.facebook.react.fabric.events.EventEmitterWrapper;
@ -67,6 +69,9 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
if (ReactFeatureFlags.eagerInitializeFabricClasses) {
loadClasses();
}
if (ReactFeatureFlags.enableEagerInitializeMapBufferSoFile) {
ReadableMapBufferSoLoader.staticInit();
}
MessageQueueThread jsMessageQueueThread =
mReactApplicationContext
.getCatalystInstance()
@ -138,5 +143,6 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
SurfaceHandlerBinding.class.getClass();
BatchEventDispatchedListener.class.getClass();
ReactNativeConfig.class.getClass();
ReadableMapBuffer.class.getClass();
}
}