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

I really enjoy Swift's philosophy of setting up higher-level abstractions, and then pirouetting under the hood to get performance near the ballpark of C++ and family. I'm a big believer in "Just Works pretty-fast by default, optimal by deep-dive".

Too bad Apple hasn't shown much interest in supporting Swift on other platforms; I know efforts exist but they all seem like second-class citizens. I don't really want to invest the time learning a new language that's locked to a single ecosystem.




> get performance near the ballpark of C++ and family.

That's a bit of an overstatement, Swift isn't really in the same ballpark than C++. Its performance characteristics are more the like of a managed language.

In the ixi driver implementation[1], they ended-up with results comparable to JavaScript in terms of throughput[2], and C# in terms of latency [3].

[1]: https://github.com/ixy-languages/ixy-languages/blob/master/R...

[2]: https://github.com/ixy-languages/ixy-languages/raw/master/im...

[3]: https://github.com/ixy-languages/ixy-languages/raw/master/im...


The main problem with this challenge is that a) most Swift developers are more used to writing front-end code and b) the specific network card isn't available to everyone that would like to look into this problem (like people with MacBooks). So while this driver seems to spend 3/4 of it's time in retain/release and I see the word `class` everywhere and the word `inline` nowhere (while inline is used in the C version it's based on!) I just can't do anything to improve it's performance.


Yeah I had the same reaction. If you look at the source, it looks like they lean heavily on reference-types, which is a worst-case for Swift performance. Specifically running tight loops with reference-counted objects comes with a huge cost, which seems to be exactly what this code does. I would love to take a crack at optimizing it, but I can't run it on my system.

Still, Swift definitely makes some compromises when it comes to performance. ARC is pretty costly in general (in terms of time, it's pretty cheap memory-wise), thanks to heavy use of atomic operations, and copy-on-write for value types has really nice properties as far as making it easy to write correct code, but it can result in unnecessary data duplication which is hard to optimize since you're basically at the mercy of the compiler to make it mode efficient.

A lot of these problems have possible solutions which haven't been implemented yet - in the long term I'm curious how much performance could be improved since I think Swift really could be the "sweet spot" language in terms of performance and usability.


Swift has been made available for Linux for the past four years:

https://swift.org/download/#releases

https://www.digitalocean.com/community/tutorials/how-to-inst...

I’m not sure what’s missing as far as libraries, other than UIKit.


Didn't realize the Linux version was offered through the official channels. That's something.

Still, to truly compete it would need to have Windows support too. And ideally real buy-in from at least one other major tech company.


As the other poster has mentioned, IBM has put a lot of effort into server-side swift. Also Google is investing in Swift for Tensorflow, which means there is a team at Google who's job it is to work on the Swift compiler every day.

edit:

If you want you can use Swift on Google Colab right now:

https://colab.research.google.com/github/tensorflow/swift/bl...


A team that is lead by Chris Lattner, creator of Swift. Not bad!


Which is why Swift with its poor CUDA and Windows support instead of Julia.


https://dev.azure.com/compnerd/windows-swift

"Support" is the kicker - I consider C# and C++ to have Windows Support because the platform vendor publishes and provides support for their own developer tools.

Do you mean that, or maybe something closer to the level of "Support" where interested parties submit improvements, and platforms are included in the CI/CD process?


> Windows Support because the platform vendor publishes and provides support for their own developer tools.

It's not from Microsoft directly, but it's worth noting that LSP support for Swift is under active development. VSCode is probably currently the second-best IDE for Swift development.


IBM uses Swift for mobile apps https://developer.ibm.com/swift/2015/12/03/introducing-the-i... and develops Kitura (https://www.ibm.com/cloud/swift), a Swift web framework.


IBM is no longer offering that Swift mobile dev kit.

The IBM Swift Sandbox is no longer available as of January 2018.


The kit is available, the web browser sandbox isn't.


> I’m not sure what’s missing as far as libraries, other than UIKit.

It's quite usable. A couple years ago, I tried Swift for Linux when it came out, and it was a dreadful experience. But now I do things with Swift in Docker containers and basically don't think about it.

There's a few things which aren't implemented (IIRC things like XML parsing support) but it's mostly things I wouldn't use or would use a library for anyway.


A key point of this article is exactly that Swift abstractions aren't nearly as "high level" as they could be. That "ABI-resilience by default at dylib boundaries" choice, while understandable, is also quite costly in terms of added complexity to the language and implementation. We already saw this happen to a different extent with C++; I think that Rust developers just saw the writing on the wall and that's why they ultimately chose to stick with a very C-like approach, where the user needs to deal with all ABI-resilience concerns herself.


> ABI-resilience by default at dylib boundaries

Actually ABI-resilience is not the default, it is enabled by a compiler flag.

In addition to that, there are some current compiler limitations when it comes to cross-module usage of generics and inlining that affect performance. But those are not by design and can be improved in future compiler versions.


If only a compiler/runtime was somehow endowed with enough artificial intelligence to decide on optimal data structures and algorithms to provide this magical 'fast by default, optimal by fine tuning'.

High level languages are fat, inefficient, rigid and what every large corporation wants, because they share so much in common.




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

Search: