Re:Apple is rewriting Foundation in Swift
by zarzavat on Monday May 22, 2023 @12:01AM
(#36027321)
What would you use instead of ref counting? Swift is an embedded language for Apple’s own chips, they can optimize the hell out of refcounting at silicon level.
[ Parent
| on HN ]
There really is only so much you can do - especially once you've got refcount churn on objects being used across multiple threads. Swift's refcounting can get truly annoying at times.
Modern, state-of-the-art, generational GC? Not being snarky, that’s literally the comparison.
There was never any way to implement a modern GC while keeping compatibility with Objective-C, which was the primary design goal of Swift.
Apple had a bad experience with GC in ObjC with libauto and learned their lesson that C and GC just don’t mix. You can never have a truly modern GC in C, because C cannot provide any of the guarantees that a GC needs to move objects around.
Using a modern GC entails sealing the language off in a bubble. Since Swift is mostly used to interface with system frameworks, you would end up paying a cost when interfacing with the system frameworks written in ObjC, making your modern GC useless most of the time.