4 ms·
Is refcounting non-determinatistic? In what way? Like, you don't know if thread A or B will finnish last and free it?
by rightbyte 8y ago
Is refcounting non-determinatistic? In what way? Like, you don't know if thread A or B will finnish last and free it?
- pron 8y agoYes, but not just. You cannot always statically determine how many objects a particular operation on a data structure with internal dynamic-lifetime nodes would need to free -- it depends on the dynamic contents of the data structure at that point in time -- and as deallocation by refcounting GC takes time proportional to the number of freed objects, you cannot determine the cost of an operation. A simple, small (in terms of runtime size) refcounting GC does better than an equally simple tracing GC, and simple refcounting has the advantage of a significantly lower heap footprint (a tracing GC uses heap overhead to drastically reduce the cost of memory management). There is also the assumption is that Rust/C++ applications will not make heavy use of GC, all the more reason to use a simple, low-footprint one, in-line with its "cost-free abstraction" philosophy.
- vardump 8y agoAtomic refcounting consumes global, system wide resource of inter-core and inter-CPU (like QPI) communication. 20M-50M of those events per second can render your 4 CPU 128 core system frozen. Also just freeing memory can create a surprisingly long pause. Depends on allocator, of course.
- cesarb 8y ago> Atomic refcounting consumes global, system wide resource of inter-core and inter-CPU (like QPI) communication. Forgive me if I'm wrong, but wouldn't reference counters consume these global resources only when there's contention for the cacheline? Once the cacheline is in an exclusive state, there's no need to go outside the core at all.
- tlb 8y agoYes, and refcounting creates false contention. For example, a global config object is constantly having its refcount bumped up and down every time someone dereferences it, even though the actual contents are read-only. There are ways to mitigate this, but they’re complex.
- steveklabnik 8y agoOne interesting thing about rust here is that you can mitigate refcount traffic, since you can also take a regular reference to the data. You only need to increment/decrement on actual ownership stuff.
- wwright 8y agoThis is actually an excellent case where Rust can help you completely remove the need to lock and help you keep your memory safe — if you can make it clear that your config object will live longer than all threads referencing it (which shouldn’t be hard if it is truly global), then Rust will let you share it among all threads with no further overhead at all, for programmer or processor.
- vardump 8y agoYou're correct. I simplified it a bit. The point still stands, though. There's not much contention resources available, so if high system performance is desired, one should look for alternatives to avoid creating chatter between cores and CPU sockets.
- kazinator 8y agoWhen you have some object O that has a reference to a set of hundreds of thousands of other objects, and drop the last reference on O, you don't know how many of those other objects will also be traversed and have their reference hit zero. It could be none of them; it could be all of them.