<div dir="ltr">Just to clarify, when I talk about Swift, I am absolutely not talking about 1:1 port. Rewriting C in Swift is pointless if we&#39;re not going to rethink it for the language. If we collectively agree to use underlying C libraries, then compiling them directly is my preference.<br><br>That said, even if we do end up doing that short term, I&#39;d like to include plans or at least intentions to do things in Swift. I (and I&#39;m sure many of us) generally prefer working in Swift because it&#39;s safe, succinct, and clean. We also have several instances of existing HTTP parsers we could pull from, it&#39;s not like we&#39;re starting from 0 as a group.<div><br></div><div>For HTTP2, I think everyone is in agreement that a c library is the way to go. I&#39;d like to give HTTP a bit more time for opinions to come in.</div><div><br></div><div>- Logan</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Nov 4, 2016 at 5:25 AM Alfredo Delli Bovi via swift-server-dev &lt;<a href="mailto:swift-server-dev@swift.org">swift-server-dev@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg">Completely agree.<div class="gmail_msg">Also, a poor performance at that stage of the request could lead to security issues too: i.e. DDoS attacks would be easier to execute.<br class="gmail_msg"><div class="gmail_msg">
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word" class="gmail_msg"><table cellspacing="0" cellpadding="0" style="background-color:rgb(255,255,255);padding:0px;margin:0px;font-family:&#39;Lucida Grande&#39;,sans-serif;font-size:12px;color:rgb(176,176,176)" class="gmail_msg"><tbody class="gmail_msg"><tr style="margin:0px;padding:0px" class="gmail_msg"><td style="font-family:arial,sans-serif;margin:0px;padding:0px;white-space:nowrap" class="gmail_msg"><span style="color:rgb(73,79,80);font-family:&#39;Helvetica Neue&#39;,san-serif;font-size:14px;white-space:normal" class="gmail_msg">—<br class="gmail_msg"></span></td></tr></tbody></table></div></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word" class="gmail_msg"><table cellspacing="0" cellpadding="0" style="background-color:rgb(255,255,255);padding:0px;margin:0px;font-family:&#39;Lucida Grande&#39;,sans-serif;font-size:12px;color:rgb(176,176,176)" class="gmail_msg"><tbody class="gmail_msg"><tr style="margin:0px;padding:0px" class="gmail_msg"><td style="font-family:arial,sans-serif;margin:0px;padding:0px;white-space:nowrap" class="gmail_msg"><span style="color:rgb(0,0,0);font-family:Helvetica;white-space:normal" class="gmail_msg">Alfredo Delli Bovi</span></td></tr></tbody></table></div></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">
<br class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On 4 Nov 2016, at 09:50, Samuel Kallner via swift-server-dev &lt;<a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank">swift-server-dev@swift.org</a>&gt; wrote:</div><br class="m_-7436525019150986007Apple-interchange-newline gmail_msg"><div class="gmail_msg"><font size="2" face="sans-serif" class="gmail_msg">I agree with Paulo. One of Swift&#39;s strong
points is its ability to bind with all sorts of existing &quot;system&quot;
C based APIs. Especially C APIs that are extremely well tested and maintained.
We should all remember that while many of us may have taken the http_parser
from Node, Node itself took it from Nginx. This code comes with great pedigree.</font><br class="gmail_msg"><br class="gmail_msg"><font size="2" face="sans-serif" class="gmail_msg">Why should we spend time developing
an HTTP parser in Swift when we should be spending our collective time
higher up the Web Server Framework toolchain? </font><font size="3" class="gmail_msg">Alfredo
Delli Bovi</font><font size="2" face="sans-serif" class="gmail_msg"> quoted the work that was
done Dave Sperling to port the HTTP Parser Kitura was using to Swift. While
he ported the code, he did not write the complete Unit Test Suite needed
for that code. His own estimate was that writing the tests would be approximately
two to three times the effort of the original port. I also seem to remember
that the performance hit for that particular code was more than 33%.</font><br class="gmail_msg"><br class="gmail_msg"><font size="2" face="sans-serif" class="gmail_msg">Another point, which is especially true
on current Swift drivers, is that any code that is going to parse something
like HTTP requests and responses is probably going to have to work at the
byte level and not that String level. This is due to performance issues.
At the byte level its actually a lot easier to write C code, than Swift
code. This may change in the future, but lets wait until this kind of thing
gets more performant in Swift.</font><br class="gmail_msg"><br class="gmail_msg"><font size="2" face="sans-serif" class="gmail_msg">Some have said that readability is more
important than performance. I for one, who have read the http_parser code
from time to time, find rather readable for a tightly written finite state
machine. Here I also beg to disagree that performance isn&#39;t important.
In a server one wants to spend cycles doing real work for the requestor,
not figuring out what he wants you to do. To scale one needs to be performant.</font><br class="gmail_msg"><br class="gmail_msg"><font size="2" face="sans-serif" class="gmail_msg">Shmuel Kallner</font><br class="gmail_msg"><font size="2" face="sans-serif" class="gmail_msg">STSM Smart Client Platforms group<br class="gmail_msg">Tel: +972-4829-6430<br class="gmail_msg">e-mail: <a href="mailto:kallner@il.ibm.com" class="gmail_msg" target="_blank">kallner@il.ibm.com</a></font><br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><font size="1" color="#5f5f5f" face="sans-serif" class="gmail_msg">From:      
 </font><font size="1" face="sans-serif" class="gmail_msg">Paulo Faria via swift-server-dev
&lt;<a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank">swift-server-dev@swift.org</a>&gt;</font><br class="gmail_msg"><font size="1" color="#5f5f5f" face="sans-serif" class="gmail_msg">To:      
 </font><font size="1" face="sans-serif" class="gmail_msg">Logan Wright &lt;<a href="mailto:logan@qutheory.io" class="gmail_msg" target="_blank">logan@qutheory.io</a>&gt;</font><br class="gmail_msg"><font size="1" color="#5f5f5f" face="sans-serif" class="gmail_msg">Cc:      
 </font><font size="1" face="sans-serif" class="gmail_msg">Swift Server Dev &lt;<a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank">swift-server-dev@swift.org</a>&gt;</font><br class="gmail_msg"><font size="1" color="#5f5f5f" face="sans-serif" class="gmail_msg">Date:      
 </font><font size="1" face="sans-serif" class="gmail_msg">04/11/2016 00:15</font><br class="gmail_msg"><font size="1" color="#5f5f5f" face="sans-serif" class="gmail_msg">Subject:    
   </font><font size="1" face="sans-serif" class="gmail_msg">Re: [swift-server-dev]
HTTP Parser</font><br class="gmail_msg"><font size="1" color="#5f5f5f" face="sans-serif" class="gmail_msg">Sent by:    
   </font><font size="1" face="sans-serif" class="gmail_msg"><a href="mailto:swift-server-dev-bounces@swift.org" class="gmail_msg" target="_blank">swift-server-dev-bounces@swift.org</a></font><br class="gmail_msg"><hr noshade class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">I think wrapping a battle-tested C library is the way
to go. Using a C library is not the same as writing one. In our case we’ll
have to deal with C APIs anyway (POSIX), so the experience won’t be something
we’re not used to already. Pragmatically here are the pros and cons:</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">Pros</font><br class="gmail_msg"><font size="3" class="gmail_msg">- Faster to wrap a C lib than to write everything in Swift</font><br class="gmail_msg"><font size="3" class="gmail_msg">- Safer to use a battle-tested C lib</font><br class="gmail_msg"><font size="3" class="gmail_msg">- Better performance when handling strings (major current
bottleneck for Swift)</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">Cons</font><br class="gmail_msg"><font size="3" class="gmail_msg">- We need the OK from Chris Lattner</font><br class="gmail_msg"><font size="3" class="gmail_msg">- If a bug is found we have to either:</font><br class="gmail_msg"><font size="3" class="gmail_msg">  - fix it ourselves and push back upstream</font><br class="gmail_msg"><font size="3" class="gmail_msg">  - if it’s something we don’t know how to fix
we report and wait for the fix</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">I’ve been using http_parser on Zewo for over an year
and I haven’t found a single bug yet. That’s *very* unlikely to happen
if we write a Swift parser ourselves.</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">About the binary data discussion. I think something so
important like that should reside in the standard library. I don’t think
a protocol is a good idea because it promotes the creation of even more
binary abstractions which is no good. I know the proposal of a new “data”
type on the standard library falls on what I just said, *but* in a perfect
world Foundation would lose NSData in favor of the standard library Data
pretty much like it did for NSString/String. Eventually all other frameworks
would be using standard library’s Data too.</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">The feeling I got from Ted Kremenek is that we should
picture the best scenario and then see where our work might land. This
is the perfect case for that.</font><br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">On Nov 3, 2016, at 6:49 PM, Logan Wright via swift-server-dev
&lt;</font><a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank"><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg">swift-server-dev@swift.org</u></font></a><font size="3" class="gmail_msg">&gt;
wrote:</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">Following up with what Tanner and Chris said. I think
HTTP 2 is particularly difficult, and you&#39;re right chris, bringing in a
c library, even if just temporarily will help expedite the process in an
efficient way.</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">I am however pretty ardently against porting C code to
Swift as opposed to rethinking things for a Swift paradigm. If that&#39;s the
case, I&#39;d prefer to either link to the c code, or bring it into the Swift
compiler. The end result would appear to be the same.</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg"> - Logan</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">On Thu, Nov 3, 2016 at 4:46 PM Tanner Nelson via swift-server-dev
&lt;</font><a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank"><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg">swift-server-dev@swift.org</u></font></a><font size="3" class="gmail_msg">&gt;
wrote:</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" color="#5f5f5f" class="gmail_msg">Tanner Nelson</font><br class="gmail_msg"><font size="3" color="#9f9fe0" class="gmail_msg">Va</font><font size="3" color="#b1b1d2" class="gmail_msg">p</font><font size="3" color="#c0c0c0" class="gmail_msg">o</font><font size="3" color="#bfbfbf" class="gmail_msg">r</font><font size="3" color="#9f9fe0" class="gmail_msg"></font><br class="gmail_msg"><a href="tel:(435)%20773-2831" class="gmail_msg" target="_blank"><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg">+1
(435) 773-2831</u></font></a><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">On Nov 3, 2016, at 4:34 PM, Helge Heß via swift-server-dev
&lt;</font><a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank"><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg">swift-server-dev@swift.org</u></font></a><font size="3" class="gmail_msg">&gt;
wrote:</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">On 3 Nov 2016, at 19:41, Alfredo Delli Bovi &lt;</font><a href="mailto:alfredo.dellibovi@gmail.com" class="gmail_msg" target="_blank"><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg">alfredo.dellibovi@gmail.com</u></font></a><font size="3" class="gmail_msg">&gt;
wrote:</font><br class="gmail_msg"><font size="3" class="gmail_msg">There has been some discussions about this in Kitura already
(</font><a href="https://github.com/IBM-Swift/Kitura-net/issues/52" class="gmail_msg" target="_blank"><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg">https://github.com/IBM-Swift/Kitura-net/issues/52</u></font></a><font size="3" class="gmail_msg">)
and I think we can use what they found out at the moment.<br class="gmail_msg">In my opinion, if we are not able to give the same (or better) performance
we should go for a wrapper of a more performant lib, such as http_parser.</font><br class="gmail_msg"><font size="3" class="gmail_msg"><br class="gmail_msg">They claim that their port is just ~1/3 slower, that seems perfectly reasonable
to me. I’m all for using it.</font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">As far as I can tell, the package in question here is
a carbon copy of the C parser (UnsafePointers, asserts, global funcs).
The only difference is it&#39;s 1/3 slower. </font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">A big performance hit like that is not worth it unless
we&#39;re getting improved readability or safety out of the code. </font><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg"><br class="gmail_msg">I also agree with the overall sentiment that a ‘pure’ Swift solution
should be preferred.<br class="gmail_msg"></font><br class="gmail_msg"><font size="3" class="gmail_msg">Of course it’s also matter of the workload that have,
we could always start with a wrapper, so we are able to define the APIs
layer and ship a version with it and later on changing the implementation
with a pure Swift.</font><br class="gmail_msg"><font size="3" class="gmail_msg"><br class="gmail_msg">Yes, the API should sit on top of this and be essentially parser agnostic.<br class="gmail_msg"><br class="gmail_msg">hh<br class="gmail_msg"><br class="gmail_msg">_______________________________________________<br class="gmail_msg">swift-server-dev mailing list</font><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg"><br class="gmail_msg"></u></font><a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank"><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg">swift-server-dev@swift.org</u></font></a><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg"><br class="gmail_msg"></u></font><a href="https://lists.swift.org/mailman/listinfo/swift-server-dev" class="gmail_msg" target="_blank"><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg">https://lists.swift.org/mailman/listinfo/swift-server-dev</u></font></a><br class="gmail_msg"><br class="gmail_msg"><font size="3" class="gmail_msg">_______________________________________________<br class="gmail_msg">swift-server-dev mailing list</font><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg"><br class="gmail_msg"></u></font><a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank"><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg">swift-server-dev@swift.org</u></font></a><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg"><br class="gmail_msg"></u></font><a href="https://lists.swift.org/mailman/listinfo/swift-server-dev" class="gmail_msg" target="_blank"><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg">https://lists.swift.org/mailman/listinfo/swift-server-dev</u></font></a><br class="gmail_msg"><font size="3" class="gmail_msg">_______________________________________________<br class="gmail_msg">swift-server-dev mailing list</font><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg"><br class="gmail_msg"></u></font><a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank"><font size="3" color="blue" class="gmail_msg"><u class="gmail_msg">swift-server-dev@swift.org</u></font></a><font size="3" class="gmail_msg"><br class="gmail_msg"></font><a href="https://lists.swift.org/mailman/listinfo/swift-server-dev" class="gmail_msg" target="_blank"><font size="3" class="gmail_msg">https://lists.swift.org/mailman/listinfo/swift-server-dev</font></a><br class="gmail_msg"><tt class="gmail_msg"><font size="2" class="gmail_msg">_______________________________________________<br class="gmail_msg">swift-server-dev mailing list<br class="gmail_msg"><a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank">swift-server-dev@swift.org</a><br class="gmail_msg"></font></tt><a href="https://lists.swift.org/mailman/listinfo/swift-server-dev" class="gmail_msg" target="_blank"><tt class="gmail_msg"><font size="2" class="gmail_msg">https://lists.swift.org/mailman/listinfo/swift-server-dev</font></tt></a><tt class="gmail_msg"><font size="2" class="gmail_msg"><br class="gmail_msg"></font></tt><br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">_______________________________________________<br class="gmail_msg">swift-server-dev mailing list<br class="gmail_msg"><a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank">swift-server-dev@swift.org</a><br class="gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-server-dev" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-server-dev</a><br class="gmail_msg"></div></blockquote></div><br class="gmail_msg"></div></div>_______________________________________________<br class="gmail_msg">
swift-server-dev mailing list<br class="gmail_msg">
<a href="mailto:swift-server-dev@swift.org" class="gmail_msg" target="_blank">swift-server-dev@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-server-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-server-dev</a><br class="gmail_msg">
</blockquote></div>