Skip to content
PodSubs
ShowsPeopleGuestsJobsNewsEvents
More
BlogPodCred
Menu
ShowsPeopleGuestsJobsNewsEventsBlogPodCredNetworksSign in
Join nowSign in
  • Shows
  • People
  • Jobs
  • News
  • More
    • Guests
    • Events
    • Blog
    • PodCred
    • Networks
    Join nowSign in

Empower Apps

Empower Apps artwork

We Don’t Have Any Futures or Promises Anymore with Tim Condon

Oct 16, 202647 minAudio
ShareXLinkedInFacebookWhatsAppEmail

Tim Condon stops by to chat about Vapor 5, the biggest Vapor release in six and a half years. We get into dropping futures and promises for Swift concurrency all the way down the stack, Span and strict memory safety, and the new shared Swift HTTP server. Guest Tim Condon Tim Condon (@0xTim@hachyderm.io) - Mastodon Tim Condon (@0xtim.bsky.social) - Bluesky 0xTim (Tim Condon) Vapor Related Links Vapor 5 Beta - Vapor Blog What's New in Vapor 5 Beta - Vapor Blog Announcing the Networking Workgroup - Swift.org swift-http-server - GitHub Swift OpenAPI Generator - GitHub Related Episodes Year of the Server with Tim Condon - Part 1 Year of the Server with Tim Condon - Part 2 Server-Side Swift with Tim Condon Who's Wendy with Joannis Orlandos Swift Server Workgroup with Joannis Orlandos Chapters (00:00) - Server-Side Swift Today (02:29) - Vapor 5, Span & Memory Safety (13:38) - Package Flags & Dropping EventLoopFutures (18:36) - Streaming & the Swift HTTP Server (24:21) - VaporTesting & Macros (33:18) - OpenAPI & the Future of Fluent (38:48) - AI, Open Source & the New Networking APIs Watch Click here to watch a video of this episode. Transcript Click here to view the episode transcript. Support the Show ★ Support this podcast on Patreon ★ Thanks to our supporters: Thanks to our monthly supporters Steven Lipton Welcome new supporters: Social Media LinkedIn - @leogdion GitHub - @brightdigit GitHub - @leogdion Mastodon - @leogdion@c.im YouTube - @brightdigit X - @leogdion X - @brightdigit Credits Music from https://filmmusic.io "Blippy Trance" by Kevin MacLeod (https://incompetech.com) License: CC BY (http://creativecommons.org/licenses/by/4.0/)

Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.

Transcript

From the show. Tap a time to play from there.

Welcome to another episode of Empower Apps. I'm Leo Dion. Today we're once again joined by Tim Condon. Tim, thank you so much for joining us. Thanks very much for having me back. great to be back. I'm excited for today's episode because we get to hear all the big updates in Vapor 5. I'll let you go ahead and introduce yourself for those who don't know. Yes, I'm Tim. I'm one half of the Vapor core team. I'm responsible for building the main Vapor framework.

So the kind of core HTTP server that everyone interacts with or web framework that everyone interacts with. And yeah, it's been a busy few months. Awesome. What before we get started, what's been some of the big changes since the last time you were on as far as how how the whole environment of server side technologies have gone and where they've where they're headed. So I think for Swift specifically, there's just a period of maturity, I think, kind of several years ago, especially when Vapor 4 was released, it was still kind of relatively

early days. Swift has only been open sourced for three, three and a half years. So it was kind of a different time and a lot of the language features that we now can take advantage of didn't exist. In the server world, I think there's been a of a greater focus on security, especially with kind of AI making it very easy to run security checks on open source code and servers. There's a big push for post quantum cryptography as quantum computing becomes more more tangible and people get worried about encryption being broken.

And then yeah, a lot of streaming stuff, AI is taking over so people want to be able to stream responses and of reactions from especially large language models as they kind of output their responses. You mean MCP type stuff? But both MCP and also if you're talking to say the OpenAI or ChatGPT API, when you send it a prompt, it will stream back a response. So you don't get the whole response at once. You get it in kind of chunks, which is why it kind of reads out bit by bit in the apps. And so kind of that kind of usage of where things are streaming and we now got HTTP/3 as well, which is kind of another layer of complexity on top HTTP that we need to handle.

So those areas are things that we need to focus on as well. So Vapor 5, you released the beta, what was it, a couple of weeks ago? Yeah, last week I think. yeah, you wanna kinda go over kind of the big picture as far as what big changes we'll be seeing in Vapor 5? Sure, yeah. I mean, the kind of the I guess the highlight of Vapor 5 is the fact that it's six and a half years after Vapor 4 was released.

Which i which actually take that as a compliment. that means Vapor 4 has been pretty rock solid in a lot of ways. Yeah, and we've managed to not break our API, which has been very hard in some cases and a bit frustrating in others. But yeah, we've managed to have a stable API. Obviously we've kind of deprecated a lot stuff and added new APIs that we've kind of tried to move people onto. But the old APIs are still there and still work. So the main highlight for me is kind of removing six, seven years of tech debt, which is very nice to do. There was a lot deleting code, which was very satisfying.

Yes, it is. But yeah, so the main kind of highlight features for this are we don't have any concept of futures or promises anymore. That's completely gone. So there's no more trying to understand what the difference between a map and a flatMap and a tryFlatMap and a flatMapThrowing is, which was a definite confusion point for people until Swift concurrency came along. So we are now fully kind of Swift concurrency the entire stack. all the way down to the low levels of NIO where we have to jump back into a different world, but that's handled elsewhere now, which is nice. So we kind of support structured concurrency properly, which has always been a little bit of a bugbear.

We have a brand new HTTP server. the new Swift Networking Workgroup has been working on a new HTTP server. and some other folks as well, which is a modern take on what an HTTP server can be. it's very, I'm still pre-release. It requires 6.4, it requires Apple platforms 26, if you're working on platforms, because it does use all of the very latest features, which allow us to do nice things like ensuring that you can't like a connection or anything. It's impossible to do because

the compiler will not let you. So those kind of things of allowing connections to escape are not possible anymore, which should make your code safer and your server safer and stay up longer. We have better integration with the ecosystem. So there's a number of packages that have been released in the last several years that we can now properly adopt, like new Swift HTTP Types library that defines kind of HTTP concurrency types, Swift Service Lifecycle, which we can properly adopt, which... will make it lot easier to integrate other services that need start and stop capabilities and us being able to manage that or you'll be able to manage us alongside.

We use Swift Configuration so that you can choose whichever configuration type you want and it will just pick it up automatically. What else we've done? We've turned on all of the HTTP other Swift flags. So if you look at our package manifest, We have 10 or 11 flags that we enable for upcoming features and experimental features that should make the code a little bit safer and a little bit cleaner. And then outside of actual core changes, we have, we're kind of streaming by default now. So anytime you want to deal with a request body or response body, that's streaming as a kind of first class citizen.

So, which enables us to do some nice things, but we still have all the syntactic sugar on top. So if you want to just decode some JSON, that's really easy to write. There's not any more. than ever was. you said something about only supporting OS 26. Why why is that exactly? That's primarily because of the spans stuff that we're So we're making use of new Swift features that can't be backported, one of which is span, and there's a couple of others that allow us to, not currently, but when we kind of get

closer to release, should allow us to be extremely performant because for span specifically, it means we can kind of essentially safely pass a pointer through to wherever one needs to use it. So that memory is just borrowed instead of having to be allocated and copied everywhere. And then the compiler gives us guarantees that memory is not going to leak, it can't be escaped. So it's a safe, performant way of writing code. Okay, I wanna really deep dive into that. like what's there's two things post async/await that I'm not super comfortable with because of my lack of experience and knowledge.

But like the whole span memory stuff, pointer the new way to do pointers, and then and I don't know if you touch on this in Vapor 5, but like owning non copyable that stuff. How do you utilize those and w what's the advantage of them and why for instance why even do a span if you could just have a class instead? Yeah. So on the kind of point of span, so span is a relatively new type. It's been, some of it's been backported to older OS versions, but for the most part it's pretty new and the story is still ongoing.

So some of the APIs we use don't have span support. Some of the foundation types we use don't have span support yet, but they have been pitched and should land in 6.5. But essentially the idea is that span is a, view into memory that you can borrow and the compiler will put constraints on how you use that memory. So if you're, say, you wanna write some JSON to your response, so you produce some JSON, you wanna write it out, what would normally happen is you'd take your response from JSON encoder, which would be data, you then copy that data into a byte buffer, that byte buffer that would be transferred into NIO, which then be copied again, which then be copied out

when it, written to the network. Yeah. In an ideal world, would happen, what will happen is that you will create your JSON, which you will then own that data, because something needs to own the actual underlying data. And then you pass a span down into Vapor, which then passes a span down into NIO, or into the HTTP server, which then passes a span down to NIO, NIO, yeah. which means that instead of copying the data every time, you're actually just kind of passing essentially a pointer, which I think literally is a pointer, down so that it can read the memory

straight from where it was originally created and where it's owned, and then write that out straight away without having to worry about making copies and stuff like that. Now, realistically, that's not gonna happen the whole time because of back pressure and things like that, but that's the ideal view. And this, essentially, there's two big things we care about for performance. The first one is reducing the number of instructions, essentially doing as little work as possible and being as efficient as possible with code. And the second one is reducing allocations.

So if we can reduce the number of times that we need to allocate memory or make copies of data or stuff, then that's gonna make us more performant. And by using span, we don't have to do copies anywhere. And so it's the same as passing a pointer in. If you're used to writing C or C++, you just pass that pointer around that star, char star or pointer or in Swift, it's called an unsafe buffer pointer. But with span, the compiler enforces the use of the span itself and the lifetime of the span itself.

So if you try and copy that span outside of the scope of where it's being used, won't let you. The compiler will refuse to compile, which means you not have to worry about leaking memory anywhere. And it also ensures things are closed off properly as well. So that's kind of one the big benefits of using span. And it solves, it also solves a lot of the problems we've been having in the ecosystem of we need kind of some kind of generic bag of bytes type. because that isn't Data, yeah. Because data is part of foundation and there are use cases where you probably don't wanna use foundation and we wanna try and have the same API everywhere.

If the ecosystem can agree on it and we can get the necessary kind of features in Swift, which I think we're kind of almost there, then we can just pass around span. So you can own it, own the data, whatever you want, creates the data, can own it. And if you don't need to copy it anywhere, you can just pass a span around and it doesn't matter what the type is. It could be data. It could be a array of UInt8s. It could be a byte buffer. really doesn't matter. It's just a span. And if you need to read the bytes to make copies or whatever, then you can do Okay, that makes a lot of sense.

one of the flags I saw on your blog post was about something called strict memory. What does that mean exactly? So there is a setting in Swift that was introduced in, I think it was 6.3, which is strict memory checking or strict memory safety. Strict memory safety, that's one, yeah. And so this is essentially started out as a feature for interacting with unsafe code, which is C and C++, but has kind of expanded a little bit into Swift world.

So the idea is that, If you are doing any potential unsafe code, such as you're dealing directly with pointers or unsafe mutable pointers or whatever, or you're talking to any kind of C code, you can turn this on and the compiler will force you to write an unsafe call at those call sites. And without that, can either get a warning or you can turn them to errors and you'll get compile errors. And so this makes it makes you kind of think about where you're going to use these things and if there are better ways.

So as span becomes more prevalent in Swift, the cases where you need to use like an unsafe mutable pointer or unsafe mutable buffer will reduce so you won't need these. And also makes you look at your code and how you're using it as well. so you can really verify because it's very easy to find out. If you're doing unsafe stuff, can just search your codebase for unsafe and then really inspect those lines of code. It has also grown a little bit now as well because if you import a library that was written before sendable and concurrency stuff in and you have to do @preconcurrency,

that import also has to be marked as unsafe as well with this setting. because it's potentially an unsafe thing to do because you're kind of giving up sendable checking. Does this d would I gain anything with regular i iPhone apps or stuff like that, or is it strictly only if you're bringing in older Swift packages that are pre-concurrency? I mean, if you're writing iOS apps that use packages that are not annotated for sendable checking, it will force you to take a look at those dependencies and question.

can say, is this dependency still something I want to rely on if potentially it is unsafe? Because you can do @preconcurrency and it silences all the warnings from the compiler, but your code is still unsafe unless you've actually opting into full sendable checking. then your code is still potentially unsafe. So it's good way of finding those things out. Yeah, that's a really good idea. okay. We talked about well, we talked about the strict memory flag. Let's talk about some other Swift Package Manager flags you have enabled and explain

like why you're using those. yeah, so like, one that I'm quite excited by is internal imports by default. so in the Vapor 4 days and before, because all of our APIs returned futures or EventLoopFutures, we had to publicly export all of the NIO types that we were using. so if you want, if we wanted to make it easy for people to write request handlers. Instead of them also having to import SwiftNIO, we could publicly export them and makes it lot easier to write.

Which is great from a usability point of view, but from a library maintenance point of view is terrible because it means that we have now tied our public API to SwiftNIO's public API. And that then follows for everything that we were exporting. So if we wanted to ever change internally what we were using, we can't, because that would then be a major breaking change. So internal imports by default is a compiler flag that essentially tells the package manager that unless you mark your imports with the public imports, then these are internal imports

and the symbols cannot be exposed unless you opt into it. So there are times where you wanna do a public import such as In our request, we return types from the Swift HTTP Types library and we wanna make those public rather than wrapping them in our own types. So it's kind of consciously opting into those public inputs, but it does mean that the things that are now internal, we can then adopt and change. So if we wanna get rid of SwiftNIO, because internally we're no longer using it, we can remove that and we don't have to do a major version release. So that's something I'm quite excited by because the public symbols of Vapor have been quite annoying as we try to evolve things for sure.

Right, right. Yeah, I like internal by internal import by default. that's what I've been using pretty consistently. and it's just a it's a great practice to get into. It is, yeah. okay. Well let's g let's get the let's get the elephant in the room out of the way. removing removing all the event loop and future stuff. How how big of an undertaking was it?

Massive. it was, so in Vapor 4.50, which was, I think it was released in 2022, if I remember right, which is just after Swift concurrency. was like a week after, in fact, maybe even a day after Swift concurrency was enabled on macOS. We offered Swift concurrency APIs alongside our EventLoopFuture APIs. So everything was async/await. So from a public point of view, you could use async/await, but internally, we were still jumping between futures and concurrency.

So internally, most of Vapor was still built off futures. So removing them was essentially, we had to touch every part of the framework. So any kind of part we were doing, any IO operations, whether that's talking to files or talking to the network or other libraries, we were doing that with futures pretty much exclusively. So yeah, it was a massive undertaking because it was effectively meant we had a full rewrite of Vapor at that point. It was massively satisfying because like our code got so much simpler. Even things like the default middleware or the default responder, like we lost three or four nesting lines of code.

And anyone who used to work with futures knows it was a pain anytime you kind of had to deal with like a if branch or something. yeah, it was nice, but it was futures were very, very pervasive through the code base. So it was, it was a big undertaking to they work great, pre async/await. It w did what it was supposed to do, but yeah. work fantastically, but just not particularly user friendly. Right, exactly. what do you have any big challenges that you faced with that refactor or migration to async/await?

it took, I think it took me a year and a half to land that PR, which isn't just because it was difficult, but, you know, we're working on both alongside each other. So we work on Vapor 4 and Vapor 5. There was a bug fix or a feature request into Vapor 4 that would then get merged. We then have to merge that into Vapor 5 and trying to run the two side by side for almost a year and a half, I think it was, was quite difficult. trying to keep them up to date. So that was a big challenge. Yeah, I'm glad that we are now merged and Vapor 4 is now its own separate thing for sure. are you still gonna be doing anything with Vapor 4 for now?

so Vapor 4 will continue. It's still the released version of Vapor. So we will continue to do bug fixes and security releases. And then at the point when Vapor 5 is released, we will commit to a likely, but not confirmed, six month support timeline where we'll support Vapor 4 for security fixes and any serious bug fixes for six months. but the majority of the feature workers now in Vapor 5, they've branched off and they will start to diverge. Okay. I had a question about streaming, but you kinda answered that because you said one of the big things has been AI has been a big push towards streaming.

Was there something else I'm supposed to ask about that, you think, or you think we covered it? mean, the main push for going streaming first was it was a mixture between performance in that for like small request bodies, it's fine. People don't really care. You just load the whole thing into memory. But as soon as anyone wants to do anything that's even moderately big, you kind of want to be able to stream that. I mean, I'd say anything over like few hundred kilobytes is moderately big.

Okay. Not from like a major issue, but if you have a few hundred kilobytes and scale that up by 10,000 users, that's a significant amount of Right, right. I gotcha. So yeah, we want to be able to do streaming by default. And we also wanted to make streaming super simple to use as well, because previously it wasn't. So we could make use of some of the new async stuff. And yeah, the APIs have turned out really nicely. But the main thing is that it's now the same thing.

So your request handlers, don't have to choose between streaming or non-streaming. It's streaming always. And you just have like a lazy collection of the body whenever you need it or whatever needs it first. is streaming is a pretty much supported by nearly every client. Yeah, well, so there's difference between streaming at the kind of app level and streaming at the kind of HTTP level. So if you send a cURL request using cURL from the command line with like a massive file, that whole file isn't sent in one packet, it's sent in several packets, which is then...

decoded into several chunks of the kernel level, is then decoded by NIO as several chunks. So we just make it super simple to iterate over that. And if you need to load into memory because it's all JSON, sure. But if you're writing that out to disk, then you can just stream that response straight to disk and not have to worry about memory. Okay, that makes total sense. do you wanna talk about testing or the Swift HTTP server? Let's talk about talk about the HTTP server first, then we can move on to the shiny new things in Vapor.

So from what you've told me and from what I read on the blog post, there's basically we have a layer that anybody can pick up and use. that's a layer on top of SwiftNIO that's an HTTP server. And the idea being is that anybody who wants to write a competitor or another HTTP server, they can use that. so like Hummingbird could use it and now you're using that in Vapor 5. what

What what was the thought process and why this was needed and what what are some of the benefits that you've seen using it? Yeah, so so the original kind of idea or intention behind this was that everyone in the ecosystem is using NIO because it's a fantastic, well-tested, well-used, well-developed, well-maintained library. But no one's writing, wants to write like channel handler code. Yeah, like it's complex. And realistically, if you're building a web server doing HTTP,

you've got to build an HTTP server and the difference. between say the Vapor HTTP server and the Hummingbird HTTP server was pretty much nothing. Like the types are different and the kind of way things were exposed are different, but at the core level you're dealing with NIO and then handling HTTP. So the idea was that, you know, there's no point us both writing an HTTP server where we both need to handle with edge cases. We both need to handle all these different things that are done in exactly the same way.

We might as well have a shared implementation. So Hummingbird started this off in Hummingbird 2 with a kind of new HTTP server that was... in the very, very early days of Vapor 5 was what we were using and built on top of. And then the Swift HTTP server kind of spun out that idea and some of that original work to create a new HTTP server of, what could we build if we wanted to take advantage of all of the latest for features. So the idea was to build a... bidirectional streaming server that was as compiler safe as possible.

So that all of the errors that you might have, all of the program errors that you might write will become compiler errors rather than runtime errors. So that's where things like the non-escapable and non-copyable request bodies come into play. And... That then means anyone can write a very simple HTTP server. You can just depend on that and set up your route handlers. And then Hummingbird and Vapor and any other web framework on top can then add on routing and middleware and sessions, cookies and authentication and whatever else like fun

syntactic sugar on top they want. Got it. That makes a lot of sense. What else am I missing? But that's the stuff you provide on top. Yeah, so Vapor can provide routing and we can build some really nice routing, syntax sugar and fun functions with macros that we'll probably talk about in a bit. We provide session support and authentication support and our middleware types, although that might be shared as well in the future. And yeah, so it allows us to write

really nice framework on top that all of the kind low level HTTP stuff we don't have to really worry about anymore. We can just concentrate on kind of building a really nice application layer framework. So I did want to talk about VaporTesting. So what is new? I've never used the testing stuff in Vapor, I'll be honest. What what's new in v in the latest version? does it use Swift Testing now or like what what are you really taking advantage of with a new testing library?

Yeah, so VaporTesting has been around for in various iterations for many, many years. It used to be called XCTVapor. In fact, the original library was XCTVapor. And then when Swift Testing was released, we released a a VaporTesting wrapper that would work with Swift Testing. But because we've gone from futures to sort of concurrency from XCTest to Swift Testing, we had five or six different ways of you being able to write a test in Vapor or a kind of a test route, all doing different things and all not quite working the same way.

So with this major release, we took the opportunity to streamline that. And so there is now one way to write a test for an application. You can create your application and you can just call .testing on it and it will deal with routing it to the right request handler. You can configure it to be either in memory. So it never actually sends a real network request. That kind of all gets bypassed and it just gets written directly through to the responder chain. Or if you need to test things like back pressure or kind of anything where you need a real network, you can send a real request.

So it will spin up the server for you, send an actual HTTP request and then deal with that all for you. And now it is built on Swift Testing explicitly. We had to have some weirds. patch code in old Vapor where we had to detect if you're running a Swift Testing or XCTest to make sure you're in the right one because they don't play particularly nicely together. So yeah, we've gone all in to a testing one way to do it. It's really nice to streamlines and we've made it really easy to write tests.

I think no matter what kind of what you're testing. so use a Swift Testing and then you can basically choose how w from what it sounds like you can choose either r like, I don't want I don't need a full server, I just need you to test routing or I need you to test some particular feature and then you can mock that pretty easily. That's pretty awesome. Yeah, so for most people and most use cases, if you wanna test your request handlers where you wanna say, okay, well, I'm sending a a post request with a JSON body to this route and

I wanna ensure that it only allows authenticated users and it writes this to the database and then returns this response. You can do all that in memory. It's almost instant, the kind of request times, because there's no network requests. If you're talking to a database, then it adds a little bit time on. But then you have these really quick performance in-memory tests that are nice and easy to write. If you do need a real server you wanna talk to, because you might wanna test back pressure or you wanna test like TLS termination and whatever, then yeah, you can just specify a single argument and say in-memory.

If you wanna specify the port that it runs on, you can as well. but by default it will just pick a port for you that's free. And then, yeah, you can just send us the same API, you can send a real request. okay I wanted to ask about macros, but I also want to ask about Fluent. And maybe because one of the big things about Fluent was or is the use of property wrappers. for sure. And sounds like you've started introducing macros into Vapor.

Kind of what's the tension before we get into the macros and Fluent? What's the tension between property wrappers and So property wrappers and macros look very similar, but they work in entirely different ways. macros is code generation. So you annotate your code with a macro and then at compile time, it'll expand that into whatever the macro is specified into code that then gets compiled and that compiled code

is then what's shipped finally. Property wrappers are more of like a runtime thing. So you annotate your properties with a property wrapper. And then at runtime, it runs through the property wrapper and does whatever it needs to do. So because of this, are a bit restrictive in property wrappers, sorry, are a bit restrictive in what they can do at runtime. And they're also super slow. So one of the big pain points of Fluent has been that for anything where you're dealing with like a large response sets, it's really, really slow to decode all that into your

Swift. Fluent models. Okay. So yeah, so in in Vapor 5 we've started adding some macros they are purely additive for now and they are built around routing so if you want to Define a route you can define a route with your macro instead of having to go through the whole Request handler definition now and the macro will expand that for you And this allows us to do some really nice things. So number one you can define is a, an @GET macro and then an @POST macro that work really nicely.

We have a controller macro and this allows us to do things like type-safe routing. So in Vapor 4, if you wanted to pass say like an integer in the path as a path parameter, so you do like slash users slash 42, you would have to specify that as a string. you then have to convert that in your request handler and pull that out and then convert it to an int or get the library to convert it to an int for you. And make sure that the types match as well because everything was a string key. So you'd have to make sure that the parameter that you're requesting is the same that you defined in your route handler.

And it wasn't very particularly, it wasn't a great user experience. to get through it. Yeah. making a little bit better and stuff, but yeah, the definition of all string types. So with macros, what we can do is we can take advantage of the kind of code expansion and do all of that for you in a macro. And you can annotate your codes. So you can say @GET, and then you can say this path, and then you can have like Int.self as one of the path parameters and the macro will expand into

a code that pulls that out for you, it names the path parameters for you, it's all written in code, and your request handler has to have an integer as one of the parameters because you're parsing in, because you've asked it to pass in. And if it doesn't, you'll get a compile error. And vice versa. you try and pass in, specify a request handler with extra property that isn't defined in the part in the route registration, then it will also fail to So those things are really, nice. And also, hopefully the next beta should have authentication macros as well, where we can do similar things with macros so that we can make sure that if you want a user as an

authenticated user, then the macro will basically do all of that for you and give you a guaranteed user without you having to write request. req.auth.require. So I'm quite looking forward to that. But it's been a fun experience dealing with macros, I'll put it that way. What's what's your biggest headache? So I think the biggest headache with macros is from an end user's point of view, they're fantastic. From a developer's point of view, like the people developing the macros, it's painful. It's quite hard to test them.

And there are things that you would kind of assume would work that don't work. So one of the big challenges we've had is that with the authentication macros, for instance, they're written and they work and it's great and you pass in your middleware, your authentication middleware into the macro and that all works and it's great but most people won't be able to pass in like a logger or a kind of some kind of setup or a database connection into their middleware that will be the one that retrieves like the authenticated users from the database.

Right. That's really difficult with macros because of the timing of where they're evaluated, you can't say specify a connection pool on a controller and then read that in the macro that's then defined inside that controller because at the point where the macro is expanded, it doesn't have the symbols to be able to read the connection. So you get these weird compiler errors. So finding workarounds for that has been really quite painful and quite complex. of the workarounds? So Depending on you're trying to do, you can use a key path.

That works reasonably well, but it's not the nicest to write. You can use a computed property that's evaluated later that that seems to work as well. But the way that I think we're gonna go about it is with task locals and just bypass the problem entirely. Yep. So I think that I need to see how we kind of get on with the next beta in the next few kind of iterations, but I think we're gonna start to use task locals a lot more for passing things like database connection pools down to where you need them to be. That makes total sense. you know, just going off of the routing stuff too, like I've I've kind of switched towards using the OpenAPI stuff that we

have. What what are some benefits with going with routing in say Vapor or Hummingbird over just using OpenAPI? Well, I mean, the OpenAPI stuff still has to do routing. Because you can define your routes up front, the server itself needs to... Yeah. Yeah. Because... why would a user directly want to do routing? So if you want to define your own routes, there are a number of reasons. Number one is that you might not want to bother writing an OpenAPI spec.

If you're building something simple, you don't need to write an API spec. It's like another layer of complexity. And the other reason that you might want to do it is because some people like the server code to be the source of truth for the routes rather than the spec. In Swift, it's slightly different because of the way that the OpenAPI generator works. It's really nice because if you change your routes, it will recompute the functions that you need at build time. So it's very hard for those documents to get out of sync, which is a really, really nice feature. Other languages might not have that feature.

So you have to kind of manually recompute or like recalculate the routes. And it's very easy for those things to get out of sync. So yeah, Vapor 5 will support OpenAPI routes from both directions. So we'll have the same OpenAPI generator support. That PR is actually up by someone from the community, which I'll be reviewing today. So that allows you to go from a spec to your Vapor code and generate the routes that way. But we're also gonna be able to, you're also gonna be able to go from your code, run a command and it will generate a spec for you.

Next. So if you want to go that way, because some people prefer it, then you can go that way as well. I was gonna say like the the reason I've found is for things that basically are not supposed to gRPC is a example of something like that, WebSockets, things like that. That's where I've ended up having to do my own routing. and it's funny you mentioned going from code to OpenAPI, 'cause I did that years ago, and we're now trying to move everything the other way, just because the OpenAPI generator is

so nice. Yeah, and previously the going from code to an OpenAPI spec was really painful. It required an extra package. had to change the way that you defined your routes and yeah, it wasn't very easy to use. So I can make that kind of a inbuilt by default behind the traits. So we talked about it, Fluent. What's kind of the plan with Fluent right now? 'Cause that's independent of Vapor 5, more or less. So back in the very early days, Vapor 2 days, package, Vapor 1 was one big thing, but everything was in one package, which was great, but it made your app a little heavy.

So in the Vapor 2 days, all those packages kind of got split out as a means of saying, well, we can then iterate on these separately and evolve them separately and they can evolve their own paces. Unfortunately that never really happened and everything evolved alongside each other. So we're starting now to see like JWTKit for instance, it's now its own package and that's been on its own new major version for a couple of years. So it's been really nice to able to evolve that independently. And Fluent will probably be similar. So Fluent 4 will be fully supported in Vapor 5.

it works currently. If you create a new route, I'm sorry, a new project using the Vapor CLI with the Vapor 5 flag, it will create a Fluent based app for you that you can use and it works fine. So Fluent will kind of evolve independently. Gwynne, who maintains most of the Fluent, has been working on a lot of the low level stuff. So Fluent is... not just Fluent, there's all of the drivers. There's also SQLKit which converts Swift code into SQL. So those things have been worked on. And then when we have time, like every other open source project, we can start working for the five.

We have a good idea of what we wanna achieve and how we want it to work, which will be primarily macros. because we can use those to generate the code that will give us really fast models and queries, rather than having to rely on reflection of everything. But that will be released independently and separately from Vapor. I wouldn't be too surprised if we did a kind of intermediately release of Fluent, which would be a new major version that throws away all of the future based stuff and allows us to adopt. structured concurrency and some nice things that we're missing there.

But that won't be the new full featured fancy shiny thing. That will be later on down the line. Right. Yeah, that makes total sense. Is there anything excuse me? Is there anything in the database space that's changed that you'd wanna adopt in Fluent? Not massively, think. think one thing that we've already kind of started to push towards is that Fluent 4 was written as an ORM that would work with both SQL and NoSQL databases, so it supported

MongoDB as well. And I think that was a mistake. I think fundamentally NoSQL databases and SQL databases work very, very differently. Yeah, I agreed. build an ORM that works across all of them just gives you the worst of both worlds. You basically have the lowest common denominator. So yeah, think that's definitely something that will change and we will change going forward. Yeah, that's something that's kind of been decided on. all right, so we have to do it. We have to talk about AI. Mm-hmm.

Okay. how has AI affected server side Swift? I guess we've already talked about like streaming being a first class feature. I'm more I'm more interested in like what how has AI made you rethink server side stuff before we get into how AI has affected the development process? I think for server-side stuff I think it makes it a lot easier to try things out.

I think it's very coupled to the development question to be honest. I don't think AI itself has changed anything that's specific to the server world outside of the development world, other than maybe security stuff in that we have gone from maybe seeing like a security advisory or people submitting security issues once every few months. Yeah, people. Once every few months to like several a month, like a massive influx, which is a server project is particularly problematic because we handle lots and lots of requests.

And if that, if there's a way of either crashing that process, that's a big problem, or there's a way of, you know, losing data or people breaking into other people's data or that kind of thing, that's another big problem. So that has been a big effect and the times that that has or the time that that takes up is significantly more than it used to be. To be fair, some of the reports are legitimate and we've fixed quite a few things and if GitHub can... Also catch up, we should have some of security advisors coming out because they're also struggling under the weight of requests.

GitHub is struggling a lot right now, so let's GitHub's one line of reliability is struggling quite a bit, I think previously, like the main issue we have at the moment is CVE times. Okay. It used to take one to two days for a CVE to be issued to us when we requested it, which is like a... For those people that don't know, a CVE is like a global identifier, a common vulnerability. I want to say enumeration, but that's probably wrong. It's basically an ID that's given to your vulnerability in a global database that people have.

And previously we'd do the fix, we'd get the fork up, we'd fix it. We'd request a CVE that would take one to two days and then we'd publish with the CVE and that gets distributed. It's taking months to get CVEs now, which is problematic. So that's a big problem at the moment that we're facing. Yeah, what else did you want to talk about? AI development specifically, yeah. It's mixed. I think it's, AI makes it really easy to automate the stuff that you kind of, the gnarly repetitive stuff that you don't really want to bother, which is great.

It makes it really easy to prototype stuff as well. So for instance, I was working on server-sent events recently, which is a form of streaming messaging. So being able to spin up a client that can prototype that really quickly and make it work and write tests for it is really easy. I think from a open source point of view, it's like a double-edged sword. It means that we can work on a lot more things in some aspects, but. The other side of that is that we have all this code that what we do, do we trust it?

we submit it? Especially pull requests are fully AI generated. Some of them are valid, but more often than not, they're kind of overly verbose or kind of not going about it the best way. And that's time sink. So kind of our workload of managing all of open source pull requests is increased significantly as well as working on it yourself. And then the kind of funding point of view is really interesting to watch open source funding just almost drop off a cliff in the last like six months to a year. And I know lots of other open source projects are having the same thing as well, where people would rather spend the money on tokens and sponsoring open source projects because

there's a lot of, I can just build it myself. So I'll build it myself. So it's a weird time for the industry, I'll say. what's your outlook as far as like how long this is gonna last? Depends on when the investors want their money back. I don't know. think, I definitely think it feels like things are starting to turn. People are getting a bit more. We're hearing lots about companies kind of getting worried about token spends, bringing people back that they've laid off because you still need engineers to review what's going

on. It does feel like we're kind of at the peak, the top of the peak. And I think AI is going to be a tool that's always going to exist now. But I don't know what format will take and if they started charging how much it actually costs them. I think a lot of people will stop using it quite quickly. Right, exactly. what are what are some of the you said verbose pull requests, what are some of the particular issues you've run into with code generated via AI? Number one is kind of.

especially Claude really likes to comment on everything. So you just have lines and lines of comments that are like, just read the code. This is useless. And as a kind of maintainer, you have to read all the lines of code to make sure that the code that you accept is A, both valid and worthy, fits in with what you wanna do and also is secure because we're a large open source project, people rely on and we're not immune to people trying to slip back back doors and to the projects. We have to make sure that every human review is legit. So that is a problem.

But yeah, and then you get things of AI trying to reinvent the wheel and re-implementing stuff. one line of code would solve it, but here's 250 lines of code because it's come up with a new way or something. Right. Or it overdoes it and builds I think I mentioned in one of my talks how it's like trying to add a whole new retry and networking layer and it's like what what are you doing? Stop. I don't need that. Yeah, totally. before we close, are there any Swift packages you'd recommend folks check out either server side or not, that you think people should be really taking advantage of?

general packages. spot here. I think the, so from a networking point of view, or a server point of view, I think people should definitely take a look at the HTTP server library. And there's also a new HTTP client library that is out there. It's a lot more early stages than the server library. Most of it's still in the kind of API proposal stage, but there are implementations out there. But that is something that the Networking Workgroup is working on actively. And that will become the new API that Swift will use for making network requests.

So URLSession will become an implementation detail. AsyncHTTPClient will become an implementation detail. On Wasm, it will be fetch, but that will become an implementation detail. So everything should go through these new APIs. So I highly recommend people check those out. because it's likely what they will be using in a year or so. Wow. Okay, cool. Very cool. Tim, thank you so much. I look forward to seeing you again in Berlin. where can people find you online? Yeah, thanks for having me.

So people can find me online as 0xTim on Bluesky, 0xTim on Mastodon under the Hachyderm server, or you can find me at timc.dev with links to everything there. Awesome. Thank you again. People can find me on Twitter at leogdion. BrightDigit.com is my website. Take a look there. join the Patreon if you want to get early access to episodes like this and be a subscriber to the newsletter as well. thank you everybody and I will talk to you again.

Bye. Thank you very much.

Open the transcript file

Hosts and Guests

Hosts

  • Leo Dion Host Feed-stated

Guests

  • Tim Condon Guest Verified

Credit the people on this episode

Be the first to rate this episode

More episodes

All episodes
  1. Not Accessible by Default with Rob Whitaker

    Nov 16, 20261 hr 10 minAudio

    Rob Whitaker joins Leo to talk about why accessibility doesn't come for free, not even with SwiftUI. Rob, an iOS engineer specializing in accessibility, author of Developing Inclusive Mobile Apps, and a member of the...

    Credit the people on this episode

  2. You’re Better Than AI with Daniel Steinberg

    Nov 9, 202651 minAudio

    Daniel Steinberg returns to chat about Apple's Foundation Models framework and what changed in OS 27. We get into using AI only where it's appropriate, experimenting with #Playground, falling back gracefully when the...

    Credit the people on this episode

  3. Do the Wrong Thing Much Faster with Graham Lee

    Nov 2, 20261 hr 12 minAudio

    Graham Lee returns to chat about what it takes to become a software centaur: using AI to get better at the craft, not just faster. We get into why the job was never about typing code, meat proxies and Jevons paradox,...

    Credit the people on this episode

  4. Then 20 Years Later with Georg Tuparev

    Oct 26, 202643 minAudio

    Georg Tuparev stops by to chat about software that outlives its plans: projects scoped for a few months that are still in development 20 years later. We get into running a small team of physicists and astronomers, why...

    Credit the people on this episode

  5. The More You Know with Stewart Lynch

    Oct 9, 202644 minAudio

    Stewart Lynch stops by to chat about using AI to learn faster instead of just letting it write your code. We get into planning in stages before you build, why Markdown is the universal language of AI, and the tiny...

    Credit the people on this episode