5 ms·
RC is slower than a modern garbage collector, ARC (if the A means it requires an atomic increment/decrement) is significantly so. I’m not saying that it is a b
by kaba0 3y ago
RC is slower than a modern garbage collector, ARC (if the A means it requires an atomic increment/decrement) is significantly so.
I’m not saying that it is a bad choice, it is probably a good one in case of battery-powered machines with small RAMs, but I think tracing GCs get a bad look for no good reason.
- jb1991 3y agoThe A in Arc stands for "automatic." But you are right about memory usage and battery ... this is why iOS devices require less memory than Android devices for comparable performance (or better performance in some cases).
- galangalalgol 3y agoThe confusion might arise from the fact that for a rust arc, the a does mean atomic.
- kaba0 3y agoWell, automatic doesn’t add much to the picture, it’s more of a marketing name. But you are right, I used rust’s terminology here.
- galangalalgol 3y agoIndeed, in microbenchmarks the only time you see swift faster than java, c#, or go, is when the bounds checking is turned off. It is not a very performant language. I do like the syntax and semantics though.
- 1over137 3y agoWhat's the point opining on which is faster when you don't even know what ARC stands for, and thus presumably not the first thing about it? Apple's frameworks used GC before, and they switched to ARC.
- kaba0 3y agoARC can stand for multiple things and is more of a marketing name here, than anything. The relevant garbage collector algorithm is called reference counting - and depending on whether it is single-threaded or have to do it over multiple threads, it can have quite a big overhead. Also, ObjC was also ref counted AFAIK before.
- koito17 3y agoWhat Apple calls "ARC", the rest of the word simply calls "RC". Unlike in Objective-C, the vast majority of RC implementations do not need the developer to modify refcounts by hand. It was already "automatic", so to speak. Moreover, ARC itself indeed modifies refcounts atomically. If it didn't, you would not be able to reliably determine the liveness of an object shared between threads. Now ask yourself whether atomically updating dozens of integers is faster than flipping a bit across a table of pointers.
- pjmlp 3y agoBasically Apple turned Objective-C's GC failure to deal with C semantics, picked COM's approach to smart pointers, and made a market message out of it into ARC, for people that never dealt with this kind of stuff before. Like in many things where "Apple did it first".
- pjmlp 3y agoYes, everyone that points that out usually has no idea that Objective-C GC failed due to C's semantics making it quite prone to crashes, and that automating Cocoa's retain/release calls was a much more easier and safer approach than making C code work in a sensible way beyond what a conservative tracing GC will ever be able to offer, while dealing with C pointers all over the place.
- koito17 3y agoNot sure why this gets downvoted when a quick search for RC overhead in Swift reveals that it is quite high[1] [1] Figure 3 in https://iacoma.cs.uiuc.edu/iacoma-papers/pact18.pdf https://iacoma.cs.uiuc.edu/iacoma-papers/pact18.pdf --- Additionally, people comparing ARC to Objective-C's conservative GC in the replies don't seem to understand that (1) refcounting is a form of GC, often times inefficient compared to a mark-and-sweep GC, and (2) conservative GCs are quite limited and Apple's implementation was pretty bad compared to other implementations. Objective-C objects are basically all a struct objc_class* under the hood, and conservative GCs in general cannot distinguish whether a given word is a pointer. Even worse, for a conservative GC to determine whether a word points into a heap-allocated block, it has to perform a lengthy, expensive scan of the entire heap. It also doesn't help that Apple decided to kickstart the GC if your messages began with "re" (the prefix for "retain" and "release" messages, which were used all the time before ARC came around). So at one point in time, you were able to marginally boost performance of a garbage collected Objective-C application by avoiding messages beginning with "re"!