orderfile/README.md
Order files are text files containing symbols representing functions names. Linkers (lld) uses order files to layout functions in a specific order. These binaries with ordered symbols will reduce page faults and improve a program's launch time due to the efficient loading of symbols during a program’s cold-start.
CMakeLists.txt and you just need make
sure set(GENERATE_PROFILES ON) is not commented. You need to pass any
optimization flag except -O0. The mapping file is not generated and the
profile instrumentation does not work without an optimization flag.llvm-profdata to merge all the raw files and create an orderfile.adb shell "run-as com.example.orderfiledemo sh -c 'cat /data/user/0/com.example.orderfiledemo/cache/demo.profraw' | cat > /data/local/tmp/demo.profraw"
adb pull /data/local/tmp/demo.profraw .
<NDK_PATH>/toolchains/llvm/prebuilt/<ARCH>/bin/llvm-profdata merge demo.profraw -o demo.profdata
<NDK_PATH>/toolchains/llvm/prebuilt/<ARCH>/bin/llvm-profdata order demo.profdata -o demo.orderfile
For load, you need to uncomment
set(USE_PROFILE "${CMAKE_SOURCE_DIR}/demo.orderfile") and make sure
set(GENERATE_PROFILES ON) is commented.
If you want to validate the shared library's layout is different, you need to
find liborderfiledemo.so and run nm
mv demo.orderfile app/src/main/cpp
nm -n liborderfiledemo.so
The main difference between a Java app and a Kotlin app is the syntax. You can easily change this Kotlin example into a Java example.
# Kotlin
companion object {
init {
System.loadLibrary("orderfiledemo")
}
}
# Java
static {
System.loadLibrary("orderfiledemo");
}
# Kotlin
external fun runWorkload(tempDir: String)
# Java
private native void runWorkload(String tempDir);
# Kotlin
runWorkload(applicationContext.cacheDir.toString())
# Java
runWorkload(getcacheDir().toString())