ByteString optimisations of methods in HTTP parsing hot-path (#20994)

* =act #20992 prepare benchmarks for ByteString optimisations

* =act #20992 optimise common ByteString operations: drop,take,slice...

* =act,htc #15965 add ByteString.decodeString(java.nio.charsets.Charset)
This commit is contained in:
Konrad Malawski 2016-07-20 14:01:51 +02:00 committed by GitHub
parent d3ea9e49db
commit fde9d86879
12 changed files with 552 additions and 60 deletions

View file

@ -473,7 +473,7 @@ private[http] object HttpHeaderParser {
private[parsing] class ModeledHeaderValueParser(headerName: String, maxHeaderValueLength: Int, maxValueCount: Int, settings: HeaderParser.Settings)
extends HeaderValueParser(headerName, maxValueCount) {
def apply(hhp: HttpHeaderParser, input: ByteString, valueStart: Int, onIllegalHeader: ErrorInfo Unit): (HttpHeader, Int) = {
// TODO: optimize by running the header value parser directly on the input ByteString (rather than an extracted String)
// TODO: optimize by running the header value parser directly on the input ByteString (rather than an extracted String); seems done?
val (headerValue, endIx) = scanHeaderValue(hhp, input, valueStart, valueStart + maxHeaderValueLength + 2)()
val trimmedHeaderValue = headerValue.trim
val header = HeaderParser.parseFull(headerName, trimmedHeaderValue, settings) match {
@ -569,4 +569,4 @@ private[http] object HttpHeaderParser {
def withValueCountIncreased = copy(valueCount = valueCount + 1)
def spaceLeft = valueCount < parser.maxValueCount
}
}
}

View file

@ -101,8 +101,8 @@ private[http] class HttpRequestParser(
val uriEnd = findUriEnd()
try {
uriBytes = input.iterator.slice(uriStart, uriEnd).toArray[Byte] // TODO: can we reduce allocations here?
uri = Uri.parseHttpRequestTarget(uriBytes, mode = uriParsingMode)
uriBytes = input.slice(uriStart, uriEnd).toArray[Byte] // TODO: can we reduce allocations here?
uri = Uri.parseHttpRequestTarget(uriBytes, mode = uriParsingMode) // TODO ByteStringParserInput?
} catch {
case IllegalUriException(info) throw new ParsingException(BadRequest, info)
}