So ive been using atomicfu for atomics for a while...
# arrow
r
So ive been using atomicfu for atomics for a while, is there a difference in performance how they work or any benefits /downsides to arrows atomics compared to atomicfu?
s
Biggest issue atm with atomicfu is that it's not stable, and it's hard to use for libraries. Additionally, atomicfu cannot be used to pass around as a value. So you cannot create
Atomic<A>
and pass it between multiple functions, or classes. The KDoc also states that if you're only using this for a
private val
and don't have a need for the other things I listed, and are not a library author, it's advised to just use atomicfu.
r
well it seems i may want to make a switch then because my main projects are apis / libraries, is there any difference in memory footprint between the two?
s
No, it uses the same impl for JS, and Native and < JDK9. On JDK9+ atomicfu uses AtomicFieldUpdater, which imposes the limitation that it can only be used for fields.
Side-not, if you're heavily relying on atomics for primitives on the JVM there might be a slight performance upgrade to implementing your own
AtomicInt
, etc for MPP. If you look at the implementation of arrow's atomic you'll find that it's pretty straight forward to do.
r
alright thanks for the info, going to start the switch and ill say arrows atomics seem to be easier to work with.
s
If you have any more questions, I'd be happy to help ☺️