4 ms·
Maybe Swift is in reference to developer speed. From a PL / compiler standpoint it's pretty obvious that Swift is not going to match Objective C from a perform
by wting 12y ago
Maybe Swift is in reference to developer speed.
From a PL / compiler standpoint it's pretty obvious that Swift is not going to match Objective C from a performance standpoint. That's why Apple used a micro benchmark comparing a static, compiled language vs a dynamic, interpreted language (Python) for marketing purposes.
> We can’t know exactly what’s going on behind the scenes, but my hunch is some of what we take for granted in Objective-C – the straight C scalar data types – are actually classes in Swift. And the more you rely on classes, the more Automatic Reference Counting is in there somewhere, retaining and releasing like there’s no tomorrow, often for no good reason.
If they switched from primitive types to classes for built-in types, that means vtables and an additional memory lookup per element access weakening caching and memory locality.
Creating a Swift int would involve instantiating a class, incrementing the ARC count, and storing data compared to only storing data for primitive types. That explains why appending Swift's Ints to an array is so much slower than NSNumber.
On a side note, this isn't as much of a problem with Java—despite everything being implemented with vtables—because of JIT and better CPU branch prediction.
Disclaimer: I have no Objective C / Swift experience.
- spicyj 12y agoThey advertised favorable performance comparisons against both Objective-C and Python.
- mpweiher 12y agoObjC has an extreme performance range, from slower than Ruby to faster than Java with primitives (= C). It's easy to pick and choose.
- spicyj 12y agoI don't disagree; I was just clarifying on the parent's claim that Apple was benchmarking only against Python: > That's why Apple used a micro benchmark comparing a static, compiled language vs a dynamic, interpreted language (Python) for marketing purposes.
- nardi 12y ago> From a PL / compiler standpoint it's pretty obvious that Swift is not going to match Objective C from a performance standpoint. This shows a deep misunderstanding of Objective-C and Swift. Swift has way more type information at compile time than Objective-C, and thus gives the compiler much more room to optimize (in addition to being safer). My guess is we'll see Swift eventually be faster than Objective-C at just about everything. For instance, they could unbox class instances into values where possible, which is something they're probably not doing much of yet.
- mpweiher 12y agoThis applies to naive code, where you let the compiler fix it. In those cases, Swift can be better because of the reasons you mention. However, if you actually put your mind to it, for the 1-5% of code that actually matter, performance-wise, it is hard to beat the performance, and more importantly: predictability, of C.