But reference counting is (potentially) faster then garbage collection. At least under some circumstances:
- modern architecture having fast atomic fetch_add/sub
- weak memory ordering making atomic fetch_add/sub even faster (if Acquire/Release ordering is used)
- optimize the usage of reference counting by eliminating pointless reference counting, e.g. as done by Objective-C/Swift automatic reference counting (ARC). Or e.g. done when using borrows in rust for everything except the places you know you really need to clone the Atomic Reference Counter (also ARC but a different one ;=) ).
Reference counting was for a long time basically guaranteed to be slower then garbage collection because of slower atomics, no weak memory ordering and "naive" usage of reference counting introducing a lot of unnecessary reference counter increased and decreases.
But with modern hardware and compilers it's no longer as clear cut, at least in practice wrt. to modern hardware.
- modern architecture having fast atomic fetch_add/sub
- weak memory ordering making atomic fetch_add/sub even faster (if Acquire/Release ordering is used)
- optimize the usage of reference counting by eliminating pointless reference counting, e.g. as done by Objective-C/Swift automatic reference counting (ARC). Or e.g. done when using borrows in rust for everything except the places you know you really need to clone the Atomic Reference Counter (also ARC but a different one ;=) ).
Reference counting was for a long time basically guaranteed to be slower then garbage collection because of slower atomics, no weak memory ordering and "naive" usage of reference counting introducing a lot of unnecessary reference counter increased and decreases.
But with modern hardware and compilers it's no longer as clear cut, at least in practice wrt. to modern hardware.