-
Notifications
You must be signed in to change notification settings - Fork 59
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
Native SynchronizedObject implementation allocates too much #412
Comments
haitaka
pushed a commit
to haitaka/kotlinx-atomicfu
that referenced
this issue
Apr 8, 2024
…tion (Kotlin#412) * Pack "thin" lock state in a single ptr-word * Spin when "fat" state is required (it's harder to pack in a single word)
Our findings so far (copying my internal response FTR): ==== I'll give a short overview of what is wrong with synchronized objects and why it is hard to achieve what plain spinlock can achieve:
Options I see I can pursue:
|
So while we cannot reasonably fix this one yet, the outcomes are:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Native SynchronizedObject implementation allocates an instance of
LockState
on everylock()
andunlock()
call.I've compared performance of the
SynchronizedObject
and a simple non-allocationg spin-lock in uncontended case. The benchmarks can be found here. In my case, the metrics reported were as follows (greater values are better):Compose Multiplatform heavily utilizes atomicfu's
SynchronizedObject
under the hood, with theLockState
instances being the most frequent heap allocation case.Certain Compomse Multiplatfrom benchmarks experience noticeable improvement in missed frame ratio (1/3 better) if the
SynchronizedObject
implementation is replaced with a non allocating spin lock.The text was updated successfully, but these errors were encountered: