2 ms·
> A reference counter is arguably the slowest option, so Swift is out of the picture It's not that simple. Obligate refcounting has lower throughput than oblig
by zozbot234 4y ago
> A reference counter is arguably the slowest option, so Swift is out of the picture
It's not that simple. Obligate refcounting has lower throughput than obligate tracing GC but offsets that with more predictable latency, which might be good for the Swift use case. Rust uses a mix of stack-based allocation, manual heap allocation and RC - and the RC only needs to manage "owners" as determined via the borrowck, as opposed to ephemeral references. So is way more efficient than something like Swift ARC, where refcounting is essentially ubiquitous and any operations via references will incur slow atomic RC updates.
- kaba0 4y agoWell, ever seen a C++ program that seemingly finished execution, but still haven’t exited? That’s shared pointers recursively freeing up their reference trees. There is a great paper showing that RC tracks object death, while tracing GCs track object “liveness”, so its essentially two sides of the same coin. As for RC, sure, at compile time many of the work can be omitted, but atomic writes needed for the counters are fundamentally slow operations on modern architectures.
- saagarjha 4y agoYou can do reference counting without making it atomic, by prohibiting sharing across threads. It’s not fundamentally required. See Rust’s Rc, for example.
- deleted 4y ago[deleted]
- germandiago 4y agoor boost local shared ptr