https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

AnnaSkantz

03/30/2023, 2:10 PM
Hello! I am currently writing my master’s thesis where I am comparing the performance of iOS applications developed in Kotlin Multiplatform Mobile vs native Swift applications. To be able to compare them I need to optimize both compilations so that they are as comparable as possible. I have managed to optimize the Kotlin/Native compilation by adding the compiler option
-opt
to the
freeCompilerArgs
list in the
build.gradle.kts
file in the shared folder (execution time went from approx 1.4 to 0.33). Now, I have some questions: 1. What kinds of optimizations are made by adding
-opt
? (such as for instance “constant folding”, “dead code removal” etc.) 2. Are there other optimizations that I can apply? I would appreciate any input or suggestions that you have as I struggle to find documentation or information on this. If you know any good resources, let me know! Thanks!
h

hfhbd

03/30/2023, 10:02 PM
Yeah, the kotlin compiler and kotlin native lacks documentation. One option: You could always look into the sources: For example, follow this line/definition. https://github.com/JetBrains/kotlin/blob/37c776b2339fdad4142f5f5929d29de9a25df499/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ConfigChecks.kt#L33 So yeah, constant folding is done. Another option, you could create an issue or better ask in #kotlin-native And keep in mind, after Kotlinc LLVM is called. Swift uses llvm too. So you should also notice the different llvm configs, and its versions. In theory, you should be able to compare the different llvm bitcode, the "input" to llvm, comparing the equivalent kotlin code with Swift. Another important thing: The memory model! The newer versions of Kotlin uses a GC memory model, while Swift uses ARC..
a

AnnaSkantz

03/31/2023, 5:45 AM
Thank you! I did not see that there was a kotlin-native channel, will ask there too.
4 Views