Hacker News new | past | comments | ask | show | jobs | submit login

Swift’s reference counting is exactly what C code on Apple’s platforms were already doing.

And Vala’s is exactly what GObject code was already doing.




That's not C but Objective-C. From quick skim of the spec[0], it relies on macros and same autorelease pool.

There is no free lunch in software engineering, only difficulties with accepting reality.

[0] https://clang.llvm.org/docs/AutomaticReferenceCounting.html


It's both C and Objective-C.

Objective-C's refcounting is exposed to C via CFRetain/CFRelease. Long before there was ARC (the thing you cite), the bulk of the NexTSTEP and then Apple frameworks were written with Objective-C code manually doing [obj retain]/[obj release] and C code manually doing CFRetain(obj)/CFRelease(obj). There was some doc somewhere telling you the protocol.

Later, ARC came around to automate it for Objective-C code that opted in. ARC carefully mimicked the semantics of the protocol in that doc.

And then later, Swift came along and mimicked the semantics of ARC.

There is a free lunch for languages that use reference counting. That free lunch doesn't exist for GC'd languages, which introduce a semantics that is different from the ones that C code already uses.

Sorry to burst your bubble.


If reading documentation and looking into implementation details doesn't help, I welcome you to measure ARC overhead and observe the numbers with your own eyes at least once, especially in multi-threaded scenario. Might also read one of the previously posted links still, surely something will work eventually.


I’m not saying ARC is fast. Reference counting is slower than GC if what you want is throughput, unless you somehow manage to do very coarse grained RC, which is what you get in most C++ code (but then it’s far from safe).

The GC<->legacy-C interoperability problem is unavoidable. I’ve been around the block on that problem as someone who writes GCs for a living. It always devolves to some sort of ugliness.

Anyway, the fact that Vala uses GObject RC semantics is a point in favor of Vala. Folks who go that route, as Swift also did, should just be honest with themselves about the tradeoff: simpler interop, worse throughput.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: