Brent Simmons: Performance These Days

Mike Ash reports that objcmsgSend takes 2.6 nanoseconds on his Mac and 2.7 nanoseconds on his iPhone. This shouldn’t come as much surprise — we’ve known since Mike’s first report in 2007 that objcmsgSend is fast. (Though this function isn’t the only measure of Objective-C’s speed relative to other languages, it’s indicative.)

Although objc_msgSend does a hash table lookup, which should be a considerate performance hit, it still is not enough to make it noticeably slower.

But that’s the minority of your app, by far. Imagine a typical RSS reader — what percentage of the code makes up the feed and OPML parsers? Well under 1%, I’d bet. The rest might as well be in Lua or JavaScript, and users would never feel the difference, because there would hardly be a difference.

Very small gains in performance between swift and message send and other dispatching alternative wont matter if you are accessing the disk or doing any other IO/Network operation.

Instead of language performance the focus should be on developer productivity. Developer performance. That’s the thing that counts these days.

And that what normally made some language, like ruby and javascript, widely used in web and cli. Safety, while very important, still has less impact on product and developer happiness than developer productivity.

..., A scripting language, or something spiritually close, that took the best parts of Swift, but was much smaller and simpler, more supple, that ran on the Objective-C runtime — dynamic dispatch and all — would have been ideal. I could fly in that language.

I did feel like I am fighting the type system at times when I am writing swift. My most recent and notable was when implementing an async pipe (similar to Elixir pipe)

public func |>> <T, W> (left: ((T? -> ()) -> ())?, right: T -> W?) -> W? {

  guard let left = left else { return nil }

  left { leftVal in
    guard let leftVal = leftVal else { return }

  return nil

I will leave the explanation of the pipe in another post.

Even though I agree with most Brent's article, I still love Swift. It might be slower here and there, but the functional aspects of the language, the first-class immutability constructs and the powerful pattern matching just beats the dynamic dispatch for me.