Reputation: 2633
According to the ActivityManager
the startup time of my android app is about 3.6s :
I/ActivityManager: Displayed app.com.app/.Activity.MainActivity: +3s653ms
I admit that my app is maybe not fully optimized because of the root layout hierarchy and fragments inflating at the startup, but I don't think the code optimization will make me win 2s, I already shortcut the code as much as I could according my needs.
Then, inside the logcat I found something disturbing with the Check:JNI at the startup. From my app the JNI is very long to setup :
2020-04-12 22:14:04.324 12724-12724/? I/.com.socialtec: Late-enabling -Xcheck:jni
2020-04-12 22:14:04.376 12724-12724/? I/.com.socialtec: report jit thread pid = 12730
2020-04-12 22:14:05.848 12724-12757/socialtech.com.socialtech W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
2020-04-12 22:14:05.890 12724-12759/socialtech.com.socialtech W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
The JNI start to 4.3s and finish to 5.8s so it's about 1.5s to execute.
To be sure the problem was not the code optimization or view inflating, I commented all the onCreate()
from my MainActivity
in order to empty it. Without any calls, the app is empty and is starting in 2.5s but the JNI is still about 1.5s.
2.5 - 1.5 = 1s which is the time duration for my empty app.
So I assume that the JNI run time is depending of the app but how can this be so long to run even with no code running inside the app?
What the JNI is exactly depending from? Is there a way to shortcut its run to speed up my startup ?
Can I turn it off within the app ?
I'd like to my app get a total startup about +/- 2s
Upvotes: 3
Views: 690
Reputation: 76639
Late-enabling -Xcheck:jni
is the default setting for debug builds, just see the documentation.
Debug builds in general run noticeable slower than fully optimized release builds - due to JIT compilation / debugging (else you could not set any breakpoints matching the human-readable source code, but only the JVM byte-code). Getting a high-end computer (or smartphone, or both) may speed this up a little; which also would improve Gradle & emulator performance. Frankly speaking - you'll get what you have paid for.
One still could disable debug.checkjni
with adb
:
adb shell setprop debug.checkjni 0
Or disable JNI debugging in the module's build.gradle
:
android {
buildTypes {
debug {
jniDebuggable false
}
}
}
Upvotes: 1