-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Micro-optimizations and improved IOException
error handling
#2638
Conversation
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #2638 +/- ##
==========================================
+ Coverage 64.89% 65.08% +0.18%
==========================================
Files 144 144
Lines 8495 8386 -109
Branches 1535 1498 -37
==========================================
- Hits 5513 5458 -55
+ Misses 2982 2928 -54 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
But you have to fix the build 🙂
@@ -60,9 +59,9 @@ private[netty] object Conversions { | |||
|
|||
def headersToNetty(headers: Headers): HttpHeaders = | |||
headers match { | |||
case Headers.FromIterable(_) => encodeHeaderListToNetty(headers.toList) | |||
case Headers.FromIterable(_) => encodeHeaderListToNetty(headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this change 👍
@@ -176,7 +176,7 @@ object Status { | |||
Try(code.toInt).toOption.map(fromInt) | |||
|
|||
def fromInt(code: Int): Status = { | |||
code match { | |||
(code: @annotation.switch) match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for me: Is this an optional hint? Might the compiler create a switch without it? Might the compiler not create a switch with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might the compiler create a switch without it
Yes
Might the compiler not create a switch with it
No
This is very similar to tailrec
; if the compiler can create a lookupswitch
or tableswitch
, it will do it even without the annotation. However, if the annotation is present, then it'll raise an error if a lookupswitch
/ tableswitch
cannot be created from the expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx! 👍
@987Nabil CI is failing due to a 502 error from sonatype when fetching dependencies. I think the failing task just needs to be retriggered. |
This PR contains some micro-optimizations and small fixes I run across while working on other issues:
headers.get(key)
inHeaders.Native
to obtain a header value. Note that this method uses a case-insensitive key, so the behaviour should be the same as previously. The performant benefit of this depends largely on the number of headers in the request. In the added benchmark, that's ~x5 faster than the current implementationzio.http.Status
<->io.netty.handler.codec.http.HttpResponseStatus
. Using the status code to do the conversion is both less boilerplate-y but also more performant as the pattern matching can be compiled to a tableswitch.IOException
inServerInboundHandler#exceptionCaught
, check if the message is not null and that it contains theConnection reset
string. This is because when using native transports (e.g., EPoll, KQueue), theConnection reset
message is prefixed by the native method's nameCharSequenceExtensions.compare
by checking that the length of the CharSequence is the same prior to iterating the chars, and by avoiding calls totoLower
when not necessary. Performance benefit is highly dependent on different factors (in some cases, up to 1 order of magnitude), and is now en par with Java'sequalsIgnoreCase
method