Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/Servers/Kestrel/Core/src/Internal/Http/HttpParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,8 @@ internal HttpParseResult TryParseRequestLine(TRequestHandler handler, ref Sequen
if (ch == ByteQuestionMark)
{
// We have a query string
for (; (uint)offset < (uint)requestLine.Length; offset++)
{
ch = requestLine[offset];
if (ch == ByteSpace)
{
break;
}
}
var spaceIndex = requestLine.Slice(offset).IndexOf(ByteSpace);
offset = spaceIndex >= 0 ? offset + spaceIndex : requestLine.Length;
}

var queryEnd = offset;
Expand Down
30 changes: 30 additions & 0 deletions src/Servers/Kestrel/perf/Microbenchmarks/HttpParserBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@ public void LiveAspNet()
}
}

private static readonly byte[] _queryStringRequest = System.Text.Encoding.ASCII.GetBytes(
"GET /api/products/search?q=wireless+noise+cancelling+headphones&category=electronics&minPrice=50&maxPrice=400&sort=rating_desc&page=2&pageSize=24 HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n");

[Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount)]
public void QueryString()
{
for (var i = 0; i < RequestParsingData.InnerLoopCount; i++)
{
InsertData(_queryStringRequest);
ParseData();
}
}

private static readonly byte[] _shortQueryStringRequest = System.Text.Encoding.ASCII.GetBytes(
"GET /api/items?id=42 HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n");

[Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount)]
public void ShortQueryString()
{
for (var i = 0; i < RequestParsingData.InnerLoopCount; i++)
{
InsertData(_shortQueryStringRequest);
ParseData();
}
}

[Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount)]
public void Unicode()
{
Expand Down
Loading