|
|
|
|
|
by nemetroid
1021 days ago
|
|
> With ARC, you know exactly when you will release your last reference and that's when the resource is freed up. It's more like "you notice when it happens". You don't know in advance when the last reference will be released (if you did, there would be no point in using reference counting). > In terms of performance, ARC offers massive benefits because the memory that's being dereferenced is already in the cache. It all depends on your access patterns. When ARC adjusts the reference counter, the object is invalidated in all other threads' caches. If this happens with high frequency, the cache misses absolutely demolish performance. GC simply does not have this problem. > There's a reason people like ARC and stay away from GC when performance actually begins to matter. If you're using a language without GC built in, you usually don't have a choice. When performance really begins to matter, people reach for things like hazard pointers. |
|
A barista knows when a customer will pay for coffee (after they have placed their order). A barista does not know when that customer will walk in through the door.
> (if you did, there would be no point in using reference counting).
There’s a difference between being able to deduce when the last reference is dropped (for example, by profiling code) and not being able to tell anything about when something will happen.
A particular developer may not know when the last reference to an object is dropped, but they can find out. Nobody can guess when GC will come and take your cycles away.
> The cache misses absolutely demolish performance
With safe Rust, you shouldn’t be able to access memory that has been freed up. So cache misses on memory that has been released is not a problem in a language that prevents use-after-free bugs :)
> If you’re using a language without GC built in, you usually don’t have a choice.
I’m pretty sure the choice of using Rust was made precisely because GC isn’t a thing (in all places that love and use rust that is)