News for hackers. Stuff that matters.
Re:Reference count, don't garbage collect by yyyk on Friday July 29, 2022 @06:59PM (#32282655)
Reference counting is garbage collection, just a different strategy - and all these strategies tend to blur to the same methods eventually, eventually offering a latency-optimized GC or a throughput-optimized GC.

Swift is inferior here because it uses reference counting GC without much work towards mitigating its drawbacks like cycles (judging by some recent posts, some of its fans apparently aren't even aware RC has drawbacks), while more established GC languages had much more time to mitigate their GC drawbacks - e.g. Java's ZGC mitigates latency by being concurrent.

Re:Reference count, don't garbage collect by musicale on Friday July 29, 2022 @08:44PM (#32283265)
Maybe Apple just hires mediocre developers (I certainly have lots of complaints about their software and UI issues, but I would probably suspect management/priorities/schedules rather than the technical staff) but they implemented GC and Automatic Reference Counting for ObjC and found that the latter resulted in better and more consistent responsiveness, which is probably what most users care about in apps. (Apps still get compressed or paged out which can lead to annoying pauses.)

My anecdata indicate that Java apps are not as responsive as ObjC/Swift for the most part.

Re:Reference count, don't garbage collect by pjmlp on Saturday July 30, 2022 @04:32AM (#32285237)
https://github.com/ixy-languages/ixy-languages

The real reason why a tracing GC was a failure in Objective-C was due to the interoperability with the underlying C semantics, where anything goes.

The implementation was never stable enough beyond toy examples.

Naturally automating the Cocoa release/retain calls made more sense, given the constraints.

In typical Apple fashion they pivoted into it, gave the algorithm a fancy name, and then in a you're holding it wrong style message, sold their plan B as the best way in the world to manage memory.

When Swift came around, having the need to easily interop with the Objective-C ecosystem naturally meant to keep the same approach, otherwise they would need the same machinery that .NET uses (RCW/CCW) to interop with COM AddRef/Release.

What Apple has is excellent marketing.

Re:Reference count, don't garbage collect by mamcx on Saturday July 30, 2022 @11:43AM (#32287671)
> What Apple has is excellent marketing.

Whoa! Marketing? Interop with C is a MASSIVE use-case. And iOS is A LOT faster and more responsive than android. That is, right there, total proof that can't denied.

I do both, and the speed of apple way and the simplicity of bridge the C-abi is not a joke.

Re:Reference count, don't garbage collect by yyyk on Saturday July 30, 2022 @06:17PM (#32290917)
The android/iOS comparison has many more factors than GC type. I suspect the main difference is processor type - Qualcomm ARM has been very disappointing so far, and GC type doesn't even come into it.
Re:Reference count, don't garbage collect by mamcx on Saturday July 30, 2022 @10:33PM (#32292624)
Certainly, but Apple code also run on x86.

My main point actually is that Apple don't pick this route for the fun of it. It HAS a need to be performant on mobiles devices (that have less luxury to get a GC that eat Ram) and that need represent A LOT OF MONEY. You can say any step about this, including making processors, are directly or indirectly related to the need.

P.D: I don't see Rc VS Gc as enemies, but as faces of the same coin. ARC is just a way to apply some Gc lessons to naive Rc. I think naive Rc is truly worse than Gc, but smart Rc is total fine and consider it the best of both in the general case...

Re:Reference count, don't garbage collect by pjmlp on Monday August 01, 2022 @10:29AM (#32306465)
Re:Reference count, don't garbage collect by yyyk on Friday July 29, 2022 @08:50PM (#32283295)
ARC is a perfectly respectable choice by itself. What's annoying me is ignoring the improvements other GC strategies and other languages have made in the last 20 years. There's a certain section of Apple users that thinks that every choice Apple makes is the only good way to do things.
Re:Reference count, don't garbage collect by kaba0 on Saturday July 30, 2022 @02:18AM (#32284714)
And RC might be the correct choice for their devices (due to them not having much RAM, and latency being more important than throughput). But that is not true everywhere, I would even say that a good tracing GC is a better default.
Re:Reference count, don't garbage collect by KerrAvon on Saturday July 30, 2022 @01:53AM (#32284598)
Your first paragraph is only true if malloc/free counts as GC. I have seen people try to claim that free() is just manual GC. You can say that if you want, but it renders the terminology meaningless.

Any true GC strategy (== one that collects cycles) will fundamentally touch and allocate more memory than malloc/free, where reference counting is pretty close to malloc/free performance; it doesn’t need to touch any memory not involved. At OS scale, that’s a huge performance advantage. You can scope down the memory involved in GC using advanced, modern GC techniques, but you’re still going to be behind malloc/free in overall efficiency — cache efficiency, memory maintenance overhead, and additional memory required for bookkeeping. And reference counting will be pretty darn close to malloc/free.

Re:Reference count, don't garbage collect by pjmlp on Saturday July 30, 2022 @04:24AM (#32285212)
Re:Reference count, don't garbage collect by bruce343434 on Saturday July 30, 2022 @04:25AM (#32285215)
It puts that "extra memory" inside the very objects it tracks with a... reference count.
Re:Reference count, don't garbage collect by fingerlocks on Friday July 29, 2022 @08:01PM (#32283040)
What do you mean? Potential reference cycles are a compile time error in Swift. That’s the whole point of the @escaping annotation
Re:Reference count, don't garbage collect by yyyk on Friday July 29, 2022 @08:45PM (#32283270)
So this[0] wasn't current despite being edited half a year ago? I guess I'm guilty of the same mistake the post had: criticizing without understanding the state of the art on the other side (at least I didn't miss it by 20 years and on an entire subfield of Computer Science).

[0] https://stackoverflow.com/questions/32262172/how-can-identif...

Re:Reference count, don't garbage collect by jumhyn on Saturday July 30, 2022 @12:40AM (#32284336)
No, the SO post is accurate—it’s trivially easy to create strong reference cycles in Swift and @escaping annotation is only of limited use in detecting strong reference cycles. Though Swift also broadly pushes towards the use of value types for which creating reference cycles of any kind is impossible since they’re values, not references!
Re:Reference count, don't garbage collect by viktorcode on Saturday July 30, 2022 @03:23AM (#32284989)
Putting both under the same term is meaningless.

Reference counting and Garbage Collection have very clear difference: when the referenced objects are destroyed (not deallocated). In RC it happens when the count reaches zero. In GC it happens some time later. That difference is crucial for having or not having deterministic performance in your program.

Re:Reference count, don't garbage collect by brabel on Saturday July 30, 2022 @04:08AM (#32285159)
Is the Pony language's GC a GC then? It runs at determinate times, namely when a behaviour (an actors' receive function, basically) finishes running... and because actors cannot share mutable state, and immutable values with more than one owner can be handled easily by a simple common parent actor, each actor's GC is completely independent of each other.

Things are rarely as clear cut as we would want to believe.

Re:Reference count, don't garbage collect by viktorcode on Saturday July 30, 2022 @01:14PM (#32288449)
> Is the Pony language's GC a GC then? It runs at determinate times, namely when a behaviour (an actors' receive function, basically) finishes running...

It is. It might run when a behaviour finishes running, according to their docs.

Re:Reference count, don't garbage collect by Animats on Saturday July 30, 2022 @04:01AM (#32285141)
> In GC it happens some time later.

Yes. In languages with destructors/finalizers called from the garbage collector, things can get very complicated. C# and Java have this problem.

Go avoids it by having scope-based "defer" rather than destructors.

Re:Reference count, don't garbage collect by pjmlp on Saturday July 30, 2022 @04:44AM (#32285277)
Java has scope based defer since version 7, while C# has it since version 4, with the improvement on version 8 to be syntactically like defer.

With a bit of generics and lambdas, they can be made to even be more defer like.

Re:Reference count, don't garbage collect by pjmlp on Saturday July 30, 2022 @04:33AM (#32285239)