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
simon.vergauwen
11/17/2022, 7:50 AM
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
Racci
11/17/2022, 7:52 AM
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
simon.vergauwen
11/17/2022, 7:55 AM
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.
simon.vergauwen
11/17/2022, 7:56 AM
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
Racci
11/17/2022, 7:57 AM
alright thanks for the info, going to start the switch and ill say arrows atomics seem to be easier to work with.
s
simon.vergauwen
11/17/2022, 7:58 AM
If you have any more questions, I'd be happy to help ☺️