10 ms·
Swift Resistance
- unsigner 12y ago> "I cannot do it because the performance is so flipping terrible in debug mode. Trying to debug your app with optimized code is just a pain." I've been shipping PC and console games in C++ since 2000. Debug builds have ALWAYS been utterly unusable for us - what we do is run in "release" mode with optimizations, ASSERTs, and debug prints enabled, then when the problem arises, turn off optimizations in a handful of related files and recompile. Then we ship another, "goldmaster" version which strips out the asserts and prints.
- repsilat 12y agoIf this performance-critical part of the code is battle-tested, they could always compile this bit with optimisations and the rest in debug mode, too.
- drewcrawford 12y agoI wish this were true, but unfortunately you can't mix unoptimized and optimized code in Swift. File dupes of rdar://19527999.
- GuiA 12y agoBe a good citizen, file a bug report everytime you encounter problems with your tools.
- chris_wot 12y agoAre Apple responsive?
- jackweirdy 12y agoI filed a bug report for Mac mail about 3 months ago. From the bug tracker UI (which isn’t informative at all) I don’t think the ticket has even been touched.
- jakobegger 12y agoIn the last year I filed 7 bug reports to Apple. One was closed as a duplicate. For another one they requested additional information. The other 5 reports received no response at all.
- DrJokepu 12y agoI have filed 3 radars with Apple regarding Swift. All 3 bugs have been fixed.
- josephlord 12y agoMixed but the Swift team mostly yes.
- orkoden 12y agoIt usually takes weeks or months for reactions to bug reports. I have three open bugs (one for Xcode, one for iOS, one for OS X). The iOS bug is a regression introduced in the beta and reported in August. It contains screen shots and sample code. No reaction yet.
- forgottenpass 12y agoSomeone posted this to Hacker News a while ago about how submit bugs and interact with Apple. When I compare them to other software providers I have interacted with (development tools/platforms/libraries/etc), the only team looking worse than Apple is google. It's a coping guide for an abusive relationship. http://blackpixel.com/blog/2012/02/radar-or-gtfo.html http://blackpixel.com/blog/2012/02/radar-or-gtfo.html
- bitserf 12y agoOf the many bugs I reported at 8.0 release, not one has been fixed. Basic intern level stuff to do with messed up orientation bugs, broken locale APIs, text rendering and layout issues. I honestly can't be fucked any more, they can hire some QA with the billions they're earning. They can build all the fancy APIs they want, I'm not touching it until they haven't decided to discard it after a year and some other poor suckers have suffered through their eternal September of shitty buggy newness while fighting with App Store review team every second version for the privilege to make burger flipping money.
- DennisP 12y agoYeah, with $178 billion in cash, you'd think they'd beef up a bit.
- gurkendoktor 12y ago> they can hire some QA with the billions they're earning I don't see how that would help at all. Many of these bugs HAVE been discovered and reported on Radar. If Apple's deadline is September XY for iOS Z, and November XY for OS X 10.Z, then they will ship it, no matter what their QA team says, and no matter how big it is. iOS 8.0.1 was a QA glitch, but I'd say it was an outlier.
- mikeash 12y agoI strongly object to this notion that I have to give free work to Apple in order to "be a good citizen." I understand that if I expect stuff to get fixed that my odds are improved if I file a bug report. But I don't owe Apple anything and I'm perfectly within my rights, and still a "good citizen" if I just do my best to work around the problems and let Apple figure stuff out on their own.
- CmonDev 12y agoA gentle introduction to Apple marketing: "Swift" doesn't mean "swift" - terms and conditions apply (not to mention the name was stolen from the original Swift language - modifications made to Wiki were swift indeed).
- te_chris 12y agoMy problem with swift is even more simple than this guy's. I have a new client build and really wanted to use swift for the compile time safety features. Then I started looking at ios7 compatibility...total fucking joke. After isolating what is still a very popular device, especially by revenue in the case of my client, apple have basically made it impossible use this language as long as people have customers who use an iPhone 4. In this case, for my client, that's fucking heaps of them. It doesn't have to be this way though, they could prioritise adding support for static libs,then all developers will be able to switch over as we'll be able to use the existing libraries we rely on, but they just don't seem to give even half a shit about making it something people might actually use. /end rant
- tljr 12y agoI still have to support WinXP.
- sneak 12y agoOr they could just wait a year for the iPhone 4 to go away, and focus their attentions on building a watch for people to firehose money at them for. Seems pretty simple to me. Skate to where the puck is going.
- jakobegger 12y agoI think the puck is going in the direction of an ever increasing number of people who buy used iPhones. So I don't think that the iPhone 4 is going away soon. Looking around, I see that a lot of people who can't afford (or don't want to afford) new iPhones are starting to buy used iPhones instead of cheap new phones.
- illumen 12y agoI've seen this in various circles. People seem to be getting used iphones pretty cheap. Some of them even buy apps.
- te_chris 12y ago
- oulu2006 12y agoI can't help but feel like we continue to just go backwards; Swift doesn't look like they spent much time really thinking about what they wanted to solve and how to solve it. I thought this was an interesting read: http://owensd.io/2014/09/24/swift-experiences.html http://owensd.io/2014/09/24/swift-experiences.html I know saying this is a bit terse, but a native Clojure compiler for iOS would have been the best thing Apple could have done -- let someone else with far better language skills who has already done a lot of thinking about values, identity, state and time solve it and then just use the work.
- b3tta 12y agoSomehow it seems that currently everything happening in the USA is "Dead on Arrival" - including Swift. This time due to shipping an utterly broken compiler to an unfinished language, without being able to contribute to it. Because if we could contribute to it, Swift might still be soon something that people love to use. But I somehow really don't believe that this will ever truly happen.
- coldtea 12y ago>Because if we could contribute to it, Swift might still be soon something that people love to use. Yeah. Like D, Haskell, Hurd, LaTeX3e and all the other "open for contributions" stuff that people can't get enough off...
- b3tta 12y agoI'm not really sure how to interpret your comment, since it is possible to contribute to all of those and they are de facto loved by the community…
- tommi 12y agoHow well do you see Clojure as a language fitting in the UIKit patterns?
- oulu2006 12y ago
- austinz 12y agoThe article discusses two Swift versions of the same program, one that uses UnsafeMutablePointer (which is basically direct C-style memory access), and one that uses Swift's built-in Array type. The former runs well, the latter is slow. If you look at the Objective-C code, BackingBuffer is a C struct containing a C array of Pixels (themselves each a 32-bit C struct). The problem is that the best analogy to Swift's Array type is not the C array in Objective-C - it's the Foundation class NSArray. For the given use case, most Objective-C developers would eschew NSArrays and classes serving as data bags in favor of fixed-length C arrays containing C structs. C arrays don't perform bounds checking, they require you to manually decide when to allocate, copy, and free the backing memory, they require you to know how much space each piece of data requires and work with the data accordingly, and so forth. The fact that NSArrays can't hold value types, only references to classes, complicates things a bit, but I doubt the Objective-C code would be anywhere as fast if the backing store was an NSArray holding NSValues or something similar. Comparing the Swift implementation using Arrays to the Objective-C implementation using C arrays is not really fair.
- mpweiher 12y agoSo what should he use instead?
- austinz 12y ago> UnsafeMutablePointer (which is basically direct C-style memory access)
- kybernetyk 12y agoUnsafeMutablePointer<UInt8> Which he somehow dismisses but is the corresponding thing to an unsafe C array. I'm not a big fan of Swift but this rant is rather unfounded. Sometimes you have to give up high level abstraction for performance. In Obj-C he was willing to do so by using an C array. In Swift on the other hand he insists on using the high level array implementation.
- Kurtz79 12y ago
- deleted 12y ago[deleted]
- oofabz 12y agoHe has the solution to his own problem. He just needs to use the unsafe array. People have been writing quality games for decades using unmanaged memory access. It is not some ticking time bomb that will inevitably blow up your app. It just requires a little more care to get right. Considering this guy is manipulating pixels directly and writing his own blitter, I believe he has the skills to pull it off. I can understand why he would prefer to use managed code but it's not compatible with his goals and he has a clear alternative. His issue is not Swift's fault, it's his refusal to use the tools that Swift gives him.
- lerno 12y agoIn theory Swift's arrays are little more that a c array + length, and this is how we have been encouraged to use them. The issue here is nothing about "managed code", but about how the Swift compiler behaves without any optimization passes. Currently (and it should be noted that this is a recognized issue), the unoptimized builds are orders of magnitude slower than ObjC because Swift will auto refcount code that in ObjC is either not ref counted at all, or uses manual RC. After optimization, Swift can eliminate many uses and put things on the stack etc, but we are at the mercy of the optimizer for that. Compare this to the (compararively) predictable behaviour you have in C. Yes we can in theory use UnsafeMutablePointer everywhere, but in that case it's much more efficient to write the function in C instead.
- mikeash 12y agoI would wager that the problem is that Swift arrays aren't just a pointer plus a length, but rather a pointer plus a length plus copy-on-write semantics. You probably need some smart optimizations to eliminate the copies, and I'd put good odds on the performance problems here coming from lots of unnecessary array copies.
- lerno 12y agoI'd have to check in detail, but just looking at the profiler, about half of the time is in the actual setter code and half in bounds checking. One would think that bounds checking is a faster operation than the set if copy-on-write is the culprit? But maybe it does some other magic as well. Something you notice though is that release/retains are everywhere.
- zelos 12y agoThe last benchmarks[1] I saw for Swift showed it's generally pretty slow without optimisations on, but various differences in the language from Objective C mean the compiler can optimise it much more, so generally it's faster than Objective C (and actually comparable to pure C at times[2]). [1] http://www.jessesquires.com/apples-to-apples-part-two http://www.jessesquires.com/apples-to-apples-part-two [2] http://www.jessesquires.com/apples-to-apples-part-three/ http://www.jessesquires.com/apples-to-apples-part-three/
- mpweiher 12y agoThose benchmarks (part 2) were ludicrously flawed, comparing native integers in Swift with NSNumber objects in Objective-C. The fact that the standard library qsort() routine, which uses function pointers and pointers to the objects to be sorted in the array has overhead is also obvious, a truly native implementation is still much better[1] [1] http://blog.metaobject.com/2014/09/no-virginia-swift-is-not-10x-faster.html http://blog.metaobject.com/2014/09/no-virginia-swift-is-not-...
- josephlord 12y agoOne significant thing slowing this down is all the access to the the shared mutable buffer. I'm confident it would go quicker if renderWeirdGradient was changed to be a pure function that either returned a new populated buffer or had the buffer as an argument and returned the result. An even quick fix that would have some improvement would be to make the buffer final so that less indirections are required to read and write from it. As others have already said the unsafeMutableBuffer may be appropriate for performance critical inner loops.
- josephlord 12y agoI've just tried making the buffer final and it results in a speedup of 8 times (not rigourously measured). From ~0.02 to between 0.0045 and 0.0025 on my computer.
- josephlord 12y agoPull requests sent with both suggested changes. Both have a similar speedup effect (making the buffer final is if anything the bigger effect).
- josephlord 12y agoThis PR puts the Swift array on terms I think: https://github.com/owensd/handmade-swift/pull/1 https://github.com/owensd/handmade-swift/pull/1 The final keyword means that at least one indirection is avoided for each access to the buffer. The speedup is significant. I do wonder if there is a way that the lookup could be cached though if the compiler was a bit smarter. There is also the option of using a pure function rather than accessing the instance buffer for fairly similar performance (see: https://github.com/owensd/handmade-swift/pull/2 https://github.com/owensd/handmade-swift/pull/2)
- zghst 12y agoInstead of wholly claiming Swift is slow (with your limited expertise in the language, as well as running no optimizations), why don't you reach out to see what you can do to improve performance? Sid you reach out to anyone to see what you can do to improve performance / if you are doing things the Swift way?
- lstamour 12y agoThis blog post is a reaching out, and the article clearly points out that with optimizations it runs fine, but that you can't always run with optimizations enabled, e.g. when debugging or stepping through sections.
- LeoNatan25 12y agoI guess you couldn't be bothered to read beyond the title, could you?
- geoelectric 12y agoI like how he blew past the suggestion to turn off bounds checking in the comments (which I assume otherwise shouldn't affect the ability to debug), when that looks like almost certainly the reason why the array version is a couple orders of magnitude slower when unoptimized.
- josephlord 12y agoI've posted this response: http://blog.human-friendly.com/the-importance-of-being-final http://blog.human-friendly.com/the-importance-of-being-final Separately I got excellent optimised performance with a final class and this renderWeirdGraphics method which outperforms the Objective-C version by 40% in optimised builds: func renderWeirdGradient(blueOffset: Int, _ greenOffset: Int) { let height = buffer.height let width = buffer.width buffer.pixels.withUnsafeMutableBufferPointer { pixels->() in for y in 0..<height { let row = y * width for x in 0..<width { let i = row + x pixels[i].green = Byte((y + greenOffset) & 0xFF) pixels[i].blue = Byte((x + blueOffset) & 0xFF) } } } self.needsDisplay = true }