[swift-server-dev] [HTTP] Value vs Reference Types

Helge Heß me at helgehess.eu
Wed Nov 23 17:29:13 CST 2016

On 24 Nov 2016, at 00:09, Dan Appel <dan.appel00 at gmail.com> wrote:
> I think it's important to make the distinction between performance and semantics, but just to address this...
> >Unless you are talking about just the HTTP message head (which is not much more than a specialised dictionary), it doesn’t make any sense to me to pass them around as values.
> >
> >The body's of the HTTP messages can be gigabytes big and won’t usually be stored in-memory at all or at least as-is. Processing state on the body stream needs to be passed around as a reference.
> The other point you raise is that the body may be a stream, at which point it is impossible to copy around.

The body of a HTTP message is by definition always a stream. You can opt to load the stream into a buffer (either memory or disk), but that is rarely what you want in server applications.
Almost certainly not for responses, but the requests are not really that different either (you want to support uploading photos/videos and such ...)

> Copying the message around will keep a reference to the same stream, but since its immutable this isn't an issue.

Elaborate. If a stream is attached the immutability property of the message is essentially void and rendered pretty much useless? (as you can’t pass it around anymore as-if-new, that only makes sense if the body too is part of the immutability contract).

You also seem to ignore trailing headers which are only coming in while the HTTP body stream is being processed.

> I urge you to reconsider your stance. Just because something can be very large doesn't immediately mean it should be a reference type.

Well, but this is what you are doing to? You are keeping the streams as a reference type. Why? ;-)


More information about the swift-server-dev mailing list