Hi guys! Our multiplatform iOS app freezes when ru...
# multiplatform
p
Hi guys! Our multiplatform iOS app freezes when run from XCode after upgrading Kotlin to 1.9.2 (from 1.8.22) In 10 seconds iPhone CPU usage goes from 20% to 200% and then the app freezes completely. Looking into XCode CPU profiler, the source of the load is “GC finalizer processor” thread, which is loaded 200%. See profiler screenshot below. This happens only while development (the app launched from XCode). This happens on a physical iPhone only. No freeze on the simulator. No freeze, if the iPhone is NOT connected to Mac. No freeze on Kotlin 1.8.22. A really weird issue. I wonder if anyone has noticed a similar behavior after upgrading to Kotlin 1.9?
1
👀 1
The same issue with 1.9.20 Anyone?
t
Hi! Is there any way you could you share a reproducer project?
p
Timofey, thank you for getting back. This happens in our production project. Unfortunately, It's huge and we are hesitant to open the code base to the world.
We have found the source of the problem and the solution. Since 1.9.0 Objective C objects are released on the main thread. For some reason this change made our app running very slow. Fortunately, there is an option to revert to the old GC behavior. Add this to gradle.properties
kotlin.native.binary.objcDisposeOnMain=false
Context https://kotlinlang.org/docs/whatsnew19.html#objective-c-or-swift-object-deallocation-hook-on-the-main-thread The issue https://youtrack.jetbrains.com/issue/KT-63232
K 1
t
I too was having issues with the GC threads taking > 100% of the CPU and hanging the app for long durations of time. I added the flag above in gradle.properties and now everything behaves as I would hope. My questions now are: can this result in anything else breaking in the future? Why was this behavior changed in the first place (this might answer the first question)? I am using a lot of Compose MP, so I expect there to be a lot of GC going on in the system...
s
I am also facing the same issue, even after adding the flag our apps, CPU utilisation on simple two screens, it staying at 100%, resulting huge battery consumption and gets the iPhone heated, CPU utilisation drops to 1 or 3% around ~1min, How can make it release more frequently ? Does anyone has any suggestion to avoid high CPU usage on iOS app?
t
Did you try changing to use the mimalloc GC?
s
Yes still behaviour is same.
@tylerwilson
Copy code
configure(listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
)) {
    this.compilations.configureEach {
        compilerOptions.configure {
            freeCompilerArgs.add("-Xallocator=mimalloc")
        }
    }
}
This is what I have tried for mimalloc, did I missed anything ?
407 Views