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

Anyone here using Swift on the server? Perhaps something in production even?



Starting about three years ago, I taught myself to build sites with Kitura, and got pretty far with it. As someone who has been paying the bills entirely with PHP since 2007, I loved the strong typing and great tooling, and I was hoping to get in on the ground floor and establish myself as an expert so I could get scooped up by an early adopter, or (gasp) maybe even IBM themselves. But those opportunities never materialized, and I got discouraged about a year ago after IBM made the baffling decision to release a new version of their database library, Kuery, which made it unusable in any non-asynchronous way (barring silly hacks), which doesn't really make sense in terms of web development. Sure, you could still use other database libraries instead, but then you're out of the IBM ecosystem. It was a weird decision and one has to wonder if IBM was eating their own dog food.

At any rate, I'd love to get back into it one of these days, but for now, PHP projects have paying clients, so that's still what I focus on. I would also like to see Swift get more "official" attention outside of Ubuntu; specifically I want it on the BSDs, though of course other Linux distros deserve it too. I'll gladly use Ubuntu if a client pays me to, though.


I do, without good reason. I never programmed for iOS. I learned it for fun and now it's my favorite language. I use IBM Kitura for server-side development because of it's well designed API.

The ecosystem is indeed the greatest downside. A lot of the existing libraries are also polluted with UIKit code making them unusable on Linux. Just recently wanted to use an existing API client of some social network, but couldn't, because it contained UIKit code. Forking it and fleshing out the parts needed feels kinda wrong.


I was thinking about it, however I've found that String performance is horrible (at least with Japanese strings) if you do anything like hasSuffix() or hasPrefix(). I think the problem is that String converts to unicode code points as soon as it seems useful, instead of keeping everything in UTF-8 (or whatever, really) and doing memcmp for hasSuffix() and hasPrefix() specifically, which would work much faster. Using NSString everywhere is faster, but then string concatenation involves a bunch of casting.

I'm not much of a server guy, so I might be wrong here, but dealing with strings seems like something a server is likely to need to deal with. Although, maybe the strings are short enough that it's not much of a problem, or maybe strings that are almost always ASCII are fast. Anyway, something to keep in mind.


Were your performance problems before or after Swift 5's switch to using UTF-8 as the preferred encoding? See https://swift.org/blog/utf8-string/ . It sounds like before, so you may want to check out the String performance again.

Swift 5.0 and 5.1 each supposedly made some 10-20% gain in ARC performance compared to the previous version (4.2 and 5.0), so that may also help. I think Swift's performance can be very hit or miss but they (Apple) are making some good strides.


It was Xcode 10.2, I think. (10.something), I think that’s Xcode 5.

hasSuffix() doesn’t need UTF-8 to be performant, though. As long as both strings are both the same encoding, just go back len(suffix) bytes from the end of the string and memcmp to see if they are equal.


You can commit a sin and make all strings be NSString


Yes.

I’ve made a backend for my app that is essentially a middleware layer to an external API.

It’s entirely written in Swift, using the Vapor web framework, packaged up in a Docker container, and hosted on Google Cloud Run (which is essentially serverless for Docker containers).

https://cloud.google.com/run/

Previously it was running on AWS Elastic Beanstalk, but the devops knowledge to get it running on Beanstalk was significantly more, and realistically beyond my capabilities. Towards the end there was an intermittent SSL issue on Beanstalk I couldn’t figure out how to fix.

Since moving to Cloud Run its been running extremely smoothly and is costing a fraction of the price.

It is in production, but the daily active users are measured in the thousands, not tens of thousands.


Yes, but it can be a pain, and I wish more people were part of the ecosystem.


Very interested in this. Would like to try it out for an AI framework that combines knowledge graphs with word embeddings and expert systems, and although the Python ecosystem is the de facto standard (despite lack of safety and performance), and Rust seems theoretically the best, Swift seems to check all the boxes in terms of safety and expressiveness for me. Swift even has a relatively huge community, but it's so focussed on iOS stuff.

I know Chris Lattner did something with TensorFlow though.

Is anyone into this?


IIRC, Chris is leading the Swift for Tensorflow team at Google.

I run a startup that utilizes CoreML pretty heavily in mobile apps, and I'm eager to eventually build out a web app with the backend entirely in Swift. Being able to do everything in one language is really enticing.


I would not because it's slow to compile, doesn't have a good backend & dev tooling ecosystem due to being bound to apple for the most part.

Kotlin would probably be a better idea, and if you really need some sort of perf boost, use rust or c++.




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

Search: