4 ms·
Very potentially. The things that can be "faster" are typically not the bottlenecks in Objective-C programs, as the fine article rightly mentions in passing.
by mpweiher 12y ago
Very potentially.
The things that can be "faster" are typically not the bottlenecks in Objective-C programs, as the fine article rightly mentions in passing.
On the other hand, a lot of the really slow parts of recent Objective-C "enhancements" are now mandatory in Swift, for example the Automatic Reference Counting (ARC) support, which is actually a big part of the 100x and more slowdowns.
Another issue is that you have copying semantics by default. The claim is that this can make things faster, but for common objects like arrays and dictionaries it first makes things a lot slower (once they fix the completely borked array semantics).
In all of these cases, you have very slow defaults that you must trust the compiler to make fast again. The claim is that the semantics make it easier for the compiler to optimize. This is true, but so far practical experience appears to be that these two don't balance, that is the compilers don't get enough extra information for optimization to compensate for the loss in performance you get from the semantics being expensive by default.
Except in well-chosen benchmarks.
In fact, even in FP languages that have much tighter semantics and therefore much better opportunities for the "sufficiently smart" compiler to do its magic, you tend to see people dropping down to nasty imperative code (effectively C in all but name) to get decent performance.
Swift's semantics are less tight, so I think it's going to depend even more on the programmer writing fast, imperative code, "C in all but name". Again, there are a few things that help the compiler here, but again I doubt they will generally be able to compensate.
I think the biggest issue with Swift performance is that it is focused on helping the compiler, rather than the programmer. The performance model is, at least so far, highly non-linear and non-intuitive. This will hopefully get better, but the semantics I've touched on make it difficult, they are inherently highly non-linear and inherently difficult to predict.
- josephlord 12y ago> Another issue is that you have copying semantics by default. The claim is that this can make things faster, but for common objects like arrays and dictionaries it first makes things a lot slower (once they fix the completely borked array semantics). But when they say "copy semantics" (actually I think it was "value semantics") they mean copy on write semantics. There are tricks that they can do to ensure the copy is pretty rare. If the array passed to a function is not used later in the calling function no copy should be needed. If it is not changed in caller or callee then no copy is needed. Yes there may be a hit at times but it should be fairly rare. I'm very glad that they are fixing the borked array semantics, I complained pretty bitterly about that.
- Wevah 12y agoIn my experience, ARC is only much slower under -O0, where the ARC optimizer isn't run.
- mikeash 12y agoWhen you say 100x slowdowns with ARC, are you talking about Swift or Objective-C? If the latter, do you have a concrete example of that happening? My experience has been that ARC is typically negligible, worst case a relatively small factor, and can be quite a bit faster due to things like autorelease elision if you hit the right situation. As for "very slow defaults that you must trust the compiler to make fast again", that applies to just about every language that wants to be fast at all. C compilers generate awful code when the optimizer is turned off.
- mpweiher 12y agoFor the 100x slowdowns, I am talking about Swift, though if you want to see a 20x slowdown in Objective-C, look here: http://blog.metaobject.com/2014/06/compiler-writers-gone-wild-arc-madness.html http://blog.metaobject.com/2014/06/compiler-writers-gone-wil... Yes, the optimizer can take care of it some times, most of the time, ..., but phew! While C compilers also generate pretty bad code when optimizations are off, it's nothing near this staggeringly awful. Unless you manage to write a longish loop that it can figure out, which is unlikely outside of benchmarks, my experience is you get around 2x or so for straight-line code that's pretty rare these days. This is 20x to 100x and more. The 2x roughly matches Probsting's Law[1], which says that advances in compiler optimizer tech. double performance every 18 years. That's not a lot, and does not justify trusting the compiler this much. In short, making the semantics slow and trusting the sufficiently smart compiler [2] to fix it has never worked in the past, and I don't see any evidence why this time should be different. [1] http://www.cs.virginia.edu/~techrep/CS-2001-12.pdf http://www.cs.virginia.edu/~techrep/CS-2001-12.pdf [2] http://c2.com/cgi/wiki?SufficientlySmartCompiler http://c2.com/cgi/wiki?SufficientlySmartCompiler