Hummingbird 2

It's strange that this issue hasn't been fixed yet. And this one too.

I doubt concurrency is the main culprit of the disappointing performance. I assume it is due to the reliance on swift-nio and its sister projects. More specifically how it propagates requests to its handlers (like middleware) to formulate a response, with each handler incurring some, even micro, overhead (storage, locking, error handling, logging, etc). I also assume Vapor suffers from the same performance dings because it too relies on swift-nio.

I could be totally wrong, but I've written a small networking library using just Foundation for the networking as a proof of concept with a Swift Macro for routing and the responses are measured in microseconds, even under heavy load, rather than milliseconds with Hummingbird or Vapor when serving the same (static) content.

1 Like

I've done a lot of benchmarking, and while I found that SwiftNIO costs some performance, it's negligible compared to the concurrency runtime's performance cost. SwiftNIO does pay some costs intentionally, for the sake of the maintainability of libraries such as Hummingbird, security (through runtime checks and API design) and flexibility.

Some examples include NIO's Pipeline, which uses existentials to pass around data. This I think wasn't possible to fix before, and is extremely challenging still today. In addition, in these projects we care about more than just latency. Throughput is another big factor, alongside memory usage, backpressure and scalability. A simple (blocking) posix socket is not representative of a system that needs to handle all of these.

A custom asynchronous library that omits some features could be faster, and provably has been in earlier projects I did before NIO 1.x was out. But I consider the worth of more performance unimportant in comparison to the reliability, scalability and security of these projects.

We designed Hummingbird 2 with the intent of leveraging improvements to the Swift compiler and runtime, sometimes even without source changes, as they are released.

7 Likes