[swift-server-dev] Proposal: Structs in place of a request-handling function
George Leontiev
georgeleontiev at gmail.com
Sun Dec 10 19:27:00 CST 2017
I have been thinking recently about how Swift can be used to enable type-safe codebases for servers with high performance requirements. I’ve prototyped some of my ideas here: https://github.com/GeorgeLyon/Server <https://github.com/GeorgeLyon/Server> (for an example see https://github.com/GeorgeLyon/Server/blob/master/Sources/Server/main.swift <https://github.com/GeorgeLyon/Server/blob/master/Sources/Server/main.swift>)
The main difference between my implementation and swift-server/http is that all of my request handlers are structs which the Server owns and mutates as data comes in. Eventually, this can enable a model with zero allocations per request. In addition, having the server own the memory that the request handlers use enable optimizations based on cache locality.
With the current design, we effectively guarantee at least one allocation per request because we process the body by returning a closure. If this function doesn’t capture anything it may be just a pointer but it is very likely it at least needs the ResponseWriter. My design doesn’t suffer from this limitation.
If this is something the community is interested in, I will gladly put together a PR,
George
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20171210/554eecf6/attachment.html>
More information about the swift-server-dev
mailing list