-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potentially harfmul SynchronizedObject usages on iOS platform #4282
Comments
Waiting for the specific coroutines version, as atomicfu got a lock upgrade recently |
Will this issue be considered solved if |
Would be nice to understand the root of the issue (it seems like it's |
I'll double-check, but after a brief refresher on the source code, I see no fault in |
Might be the case with allocation-spamming lock either, I've asked the user about coroutines version |
Thanks! The culprit seems to be https://github.com/Kotlin/kotlinx-atomicfu/blob/bad63e743ac905a298386446a82a88225c2f71fc/atomicfu/src/nativeMain/kotlin/kotlinx/atomicfu/locks/Synchronized.kt#L13-L66. There is a work in progress to replace them with a more efficient implementation on the atomicfu side, so the problem is expected to be solved in future releases. It's not going to be very soon, though, as writing efficient mutex implementations takes a lot of effort. It doesn't seem like there's evidence of coroutines using the mutex incorrectly, which was the original topic of this issue. Can this be closed? |
I suppose, but a few follow up questions:
Thanks! |
I thought this no longer happened with newer Kotlin and Compose versions? Is there a reason not to upgrade?
Yes, this would be excellent, thanks! You could share a link / an archive / whatever with me in the kotlinlang Slack (
Good point, I don't think there's a public Github issue in atomicfu for tracking this. Let's leave this one open, then, and I'll close it if we do open an atomicfu issue. |
Thank you for the reply! I've sent you my app's codebase on the Koltinlang Slack. Unfortunately, it is still happening with Compose 1.7 and Kotlin 2.1. I just profiled my app in release mode and was able to obtain the freeze. It appears most likely to happen when scrolling lists; I'll be scrolling, navigating back and forth, scroll some more, and then freeze. What's interesting is that the "long" usage of The file is too big to attach here, so I will send it to you as well. |
As another update, as I was scrolling through the same list that can sometimes cause the freezing, I got this Thread Performance Checker message:
|
We've heard that mutex implementations like our one can suffer from QoS problems (Kotlin/kotlinx-atomicfu#462), and this looks like solid proof. Thanks for the codebase! I'm sure it will be invaluable in our investigation. |
We have a report in public Slack about very slow CMP application: https://kotlinlang.slack.com/archives/C0346LWVBJ4/p1732321550585009
Luckily, the user provided an instrument profile trace, and, it's visible that some huge chunks of work are spent in our synchronization.
Notably, a good chunk (41%) of the time between 02:01 and 02:10 is spent within
kfun:kotlinx.coroutines.internal.LimitedDispatcher.obtainTaskOrDeallocateWorker#internal
->kfun:kotlinx.atomicfu.locks.SynchronizedObject#lock(){}
. It requires further investigation, but it is worth taking a lookInstruments file for the history: Hang iPhone SE CMP 1.7.0.trace.zip
The text was updated successfully, but these errors were encountered: