
Swift AWS Lambda Runtime - NobodyNada
https://swift.org/blog/aws-lambda-runtime/
======
avolcano
Is there any recent rundown on the state of server-side Swift in general? I
know there was a lot of discussion when IBM stopped working on it back in
January.

At the broadest level, I wonder what the footprint of Swift at runtime is,
both in terms of CPU and RAM. I've been really enjoying Kotlin as a server-
side language - it's a massive step up in productivity from TypeScript - but
the overhead of the JVM certainly is notable, even in small personal projects
(my small Javalin app uses four times the RAM at rest as my Express app did).
Swift is really interesting to me because it is very similar in practice to
Kotlin, but with some very cool and powerful additional language features. So,
if server-side Swift has a smaller footprint at runtime and equal or better
performance than Kotlin on the JVM[1], that'd be a really compelling language
for me.

[1] yes, I know GraalVM/native options exist for Kotlin, but every time I've
tried to investigate ecosystem compatibility, it leads to me glancing at pages
long-articles about "how to configure X framework for GraalVM" that make it
not seem worth the effort yet

~~~
akmarinov
Here’s a quick summary of things - [https://www.timc.dev/posts/future-of-
server-side-swift](https://www.timc.dev/posts/future-of-server-side-swift)

~~~
WoodenChair
Blog posts that are time-relevant should really be dated.

------
rubyn00bie
Chalk one up for time wasted not addressing what people really need...

I truly love Swift, like god-damn is it my cup of tea, but I can't really
bring myself to write it anymore. I've written over 10,000+ lines , shipped
and maintained a few different production apps, but anymore I just have no
urge to write it.

And the biggest reason why? I think it being open source is a joke until
Apple, and I mean Apple themselves, implements some sort of cross-platform UI
framework with it. Like, most of what is written in Swift is fucking UI code
that's totally useless on other platforms.

I think it's pretty laughable I can run Swift on AWS but I can't do a simple
GUI app on Linux or Windows using the OOB Swift SDK. Apple, you're a fucking
trillion dollar organization, for fucks sake stop being so damn stingy with
portability.

When I can write cross-platform GUI apps with Swift, maybe I'll give a fuck
'bout running it on a server. Just my two very bitter, hurt, and sad two
cents...

~~~
saurik
None of the other languages I use---C++, Python, Go, Rust--come with a first-
party cross-platform GUI library...

~~~
riquito
Python has first-party support for tcl/tk

[https://docs.python.org/3/library/tkinter.html](https://docs.python.org/3/library/tkinter.html)

------
mikece
If you have tons of Swift code that needs to run in watchOS, iOS, iPadOS AND
the cloud, this would kinda make sense... but how frequently is that the case?
When I was still doing mobile the goal was to write as LITTLE client-side code
as possible and put as much logic/heavy lifting on the API side as possible
because we can make changes there far quicker than in the native client. And
almost all of the client-side code was about GET/POSTing to the API or
interacting with the SDK to draw things on the screen -- almost no business
logic. That said, I didn't work much on apps that were supposed to work
without a data connection for long periods of time... in that case it's more
likely you'll run into scenarios where you're writing business logic in the
app (in Swift/ObjC) but even then the goal was to keep that kind of code to a
minimum (or less).

~~~
Eric_WVGG
Apple’s goal for Swift is to be "the new default language for computer
science." They see it as supplanting Java.

Whether you think that's crazy or not, pure server Swift is a thing,
personally I love it. [https://vapor.codes](https://vapor.codes)

~~~
pjmlp
Apple's goal for Swift is quite clear on its documentation, to replace C and
Objective-C. As for anything else it isn't quite clear.

~~~
Eric_WVGG
> The goal of the Swift project is to create the best available language for
> uses ranging from systems programming, to mobile and desktop apps, scaling
> up to cloud services. [https://swift.org/about/](https://swift.org/about/)

> "My goal for Swift has always been, and still is, total world domination,"
> Chris Lattner, the creator of Swift, said onstage at Apple's Worldwide
> Developers Conference in 2017. [https://www.businessinsider.com/developers-
> love-swift-apple-...](https://www.businessinsider.com/developers-love-swift-
> apple-programming-language-ios-apps-2020-3)

I'm having trouble finding the specific bit about "default language for
computer science," might have been his interview on the ATP podcast. anyway

~~~
pjmlp
What Chris Lattner might desire and what Apple wants isn't the same thing,
specially since nowadays he doesn't get much to say on where Swift goes.

Had he stayed at Apple overseeing the language design I would agree.

------
renewiltord
Interesting, AWS Lambda provides a runtime API so you can implement your own
runtimes. kewl [https://docs.aws.amazon.com/lambda/latest/dg/runtimes-
api.ht...](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html)

------
_31
Always happy to see more new Swift projects pop up, especially on the server
side. It's great watching the language evolve and continue to add more
powerful features.

------
happybuy
This is a great and very useful addition to the Swift ecosystem.

Currently develop a very popular iOS/macOS app in Swift which talks to an AWS
Lambda backend written in Node.js. This has required some model code to have
dual Swift and Node versions. If the Swift AWS Lambda Runtime was available
previously this wouldn't be necessary.

I'd say a lot of developers in the Apple eco-system would be in a similar
situation and this runtime can help to streamline a lot of client-server
approaches.

------
mrtksn
That’s great news. For some reason cloud function run extremely slowly for me
on Firebase. Like a few seconds slow on the first call if not called
frequently, then it drops to milliseconds level.

~~~
WrtCdEvrydy
Yeah, this is called a 'startup effect' in most cloud function environments.
Lambda has a thing called 'prewarming' which basically hits it every 15ish
seconds to make sure it's still active...

~~~
gnulinux
Does it really sleep in 15 seconds such that it needs to warm up? Why call it
every 15 seconds? Why not every hour, every day? Is there a documentation how
often it needs a warm-up?

~~~
WrtCdEvrydy
I believe AWS docs say that your function is loaded on a machine for 15
seconds after termination... so if a new request comes in during that time it
goes to that function instead of starting a new one.

------
vaxman
This is cool --finished a deep dive of SwiftNIO all the way down to the IETF
"TAPS" specification (ah, good 'ole Courier font, brings a tear to my eye).

Will my soul brother, the great chrome dome Werner Vogels, be joining the
flamboyant users of the most advanced hair care products ever invented on
stage this year during WWDC to announce new support of Apple? macOS instances
that can be spun up and down from Screen\ Sharing.app? Xcode compile farms
that work seamlessly with a new iPad Pro edition of Xcode? Apple-subsidized
(so free) access to all AWS for developers? (oh, I can dream)

If not, then there's nooo way I would use Swift outside of The "ecosystem"
(first time I've read that expression used inside of Apple's own
documentation, albeit on a GitHub project), though I might use SwiftNIO back
ported to iOS to do something cool with Multipeer and ARKit.

------
dzonga
swift is a nice language. however, don't do the mistake of developing server
side applications on it. tried it, after drinking the ibm, vapor kool-aid in
2016ish. the community though friendly is weak. still to well known stacks if
you're going to be doing server side stuff

------
ec109685
Given lambda can only possibly send one request at a time to a handler, what
is the advantage of using the non-blocking primitives and separate worker
thread versus doing work on the main thread?

~~~
sudhirj
In this model, the only advantage would be parallelism inside the request. If
you had to fetch 100 things as part of this request there’s no need to do them
one by one.

------
pier25
Anyone used compiled languages with cloud functions?

I've only used JavaScript but I'm guessing a compiled binary (eg: Go) would
have better cold starts, no?

~~~
econcon
Last time I herd c# had best cloudstart performance on lambda.

------
jtdev
All of the closure obsession in Swift is extremely off-putting to me.

~~~
magnetic
Can you elaborate?

~~~
jtdev
Closures everywhere... why? They make code difficult to reason about and read
and only seem to satisfy the FP zealots.

~~~
saagarjha
You don't have to be a functional programming zealot to be able to recognize
the value of not having to define a function just so you can sort a list using
a different predicate.

~~~
jtdev
Except that’s not the extent of how programming with closures is forced on
Swift coders.

Essential all major modern languages have collection sorting functions built
into the base collection types that accept “by” (or similar) arguments...
which is quite intuitive to even Jr. programmers.

~~~
vertex-four
OK, what's an actual example of your problem? I don't write Swift, but I'm
curious about it - where's a closure used when some fixed logic would've
sufficed?

~~~
jtdev
Did you read the parent article? Good examples there.

~~~
vertex-four
You can only get around callbacks for async IO with async/await or language-
integrated N:M threading, which is a challenging problem (I still trigger ICEs
in Rust's implementation on occasion). Java is another language which suffers
from this, and C++ only got coroutines in C++20.

~~~
jtdev
I don’t see anything in the example to indicate that the closure pattern for
Swift Lambda handlers actually allows true async.

func lambdaHandler(event: Event, context: Context) { // your lambda handler
logic... }

What’s wrong with this approach, which is how lambda handlers are written in
every other language with the exception of JavaScript - let’s not pretend that
JavaScript is a good language design reference.

Look at this Go example In comparison... simple, readable, intuitive:

package main

import ( "fmt" "context" "github.com/aws/aws-lambda-go/lambda" )

type MyEvent struct { Name string `json:"name"` }

func HandleRequest(ctx context.Context, name MyEvent) (string, error) { return
fmt.Sprintf("Hello %s!", name.Name ), nil }

func main() { lambda.Start(HandleRequest) }

~~~
vertex-four
Here's an example from the official Go documentation on using closures in the
same sort of place -
[https://golang.org/pkg/net/http/#example_ServeMux_Handle](https://golang.org/pkg/net/http/#example_ServeMux_Handle)

~~~
jtdev
Yes, closures are present in many languages, but they are pervasive and
unavoidable in Swift. You’re avoiding addressing the idea that closures
actually cause layers of (often unnecessary) indirection, make code more
difficult to reason about, and make code harder to read - especially for jr.
devs.

~~~
vertex-four
No, I'm suggesting that you've not shown they must be used any more than in
other languages - and obviously in order to make sense of the examples in Go's
documentation you've got to know how they work, and Go is pretty much _the_
language designed for junior backend devs.

