[erlang-questions] [ANN] SeqBind, Sequential Binding Parse Transformation for Erlang (Experimental)
Loïc Hoguin
essen@REDACTED
Mon Jan 16 20:25:27 CET 2012
On 01/16/2012 07:37 PM, Tim Fletcher wrote:
>> Also, accessors return the state because Cowboy doesn't try to parse or
>> read anything from the socket if it doesn't have to. That means body,
>> query string, cookies and so on aren't parsed until you need them,
>> saving resources in the process at the expense of a few more characters
>> to write.
>
> I see, but it's not *just* the extra characters, there's the mental
> overhead of having to remember to thread the state through, and
> there's the added complexity of the lazy parsing/reading which could
> be harder to debug. Whether that's a good trade-off for performance I
> don't know, but IMO it's not an API that would be easy to use.
Well the most interesting case is when receiving a POST body of a few
megabytes that you may not even want to read, Cowboy doesn't read it
from the socket until you tell it to, saving both time and memory in
cases where you don't actually need that body. Same goes for query
string/headers/cookies parsing and so on.
Whether the trade-off is good is debatable of course, and thankfully for
the people annoyed by Req1 Req2 Req3 all over the place there's now this
parse transform available. But I haven't had much negative feedback
about that.
You might also note that it's actually not that different than having a
State#state{} variable in a gen_server and modifying then returning it,
which is something people are quite used to do anyway.
--
Loïc Hoguin
Erlang Cowboy
Nine Nines
More information about the erlang-questions
mailing list