Skip to content

Commit 2a8f6c3

Browse files
davidaureliofacebook-github-bot
authored andcommitted
Add Yoga JNI bindings to libcoldstart
Summary: Yoga's JNI bindings are usually loaded during class loading, and can stall the UI thread. Here, we try to mitigate the problem by adding the bindings to libcoldstart. Reviewed By: michalgr Differential Revision: D12956818 fbshipit-source-id: 9dda5cb6d26c2bae64606bc2d7c98ab8f7c05a30
1 parent 31439f8 commit 2a8f6c3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ReactAndroid/src/main/java/com/facebook/yoga/YogaJNI.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.facebook.soloader.SoLoader;
1111

1212
public class YogaJNI {
13+
private static boolean isInitialized = false;
1314

1415
// Known constants. 1-3 used in previous experiments. Do not reuse.
1516
public static int JNI_FAST_CALLS = 4;
@@ -19,12 +20,13 @@ public class YogaJNI {
1920

2021
private static native void jni_bindNativeMethods(boolean useFastCall);
2122

22-
static boolean init() {
23-
if (SoLoader.loadLibrary("yoga")) {
23+
static synchronized boolean init() {
24+
if (!isInitialized) {
25+
isInitialized = true;
26+
SoLoader.loadLibrary("yoga");
2427
jni_bindNativeMethods(useFastCall);
2528
return true;
2629
}
27-
2830
return false;
2931
}
3032
}

0 commit comments

Comments
 (0)