-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
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
Http types slow path checks (Fixes #13268) #13269
Conversation
@normanmaurer I'm adding some notes to get feedback |
71fbe1d
to
79d55d3
Compare
// fast-path to save expensive O(n) checks; users can override createMessage | ||
// and extends DefaultHttpRequest making implementing HttpResponse: | ||
// this is why we cannot use instanceof DefaultHttpRequest here :( | ||
if (msg.getClass() == DefaultHttpRequest.class) { |
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.
@normanmaurer
It's not nice, but it would save the common path (not overridden createMessage
) to be super fast. without hitting the slow path (not implemented HttpResponse
type check)
codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseEncoder.java
Outdated
Show resolved
Hide resolved
79d55d3
to
fca9b7d
Compare
The changes on |
fca9b7d
to
6468bd1
Compare
In term of performance improvement, the micros reports...
With 6e1558f2390f95aebad5dbc17ca67dd5140ce722:
that shows an improvement both with/without websocket handlers, as stated in the commit description. |
6468bd1
to
759d587
Compare
Motivation: Http encoders/decoders and websocket handlers perform slow type checks i.e. O(N) search among all implemented interfaces for non-implemented interfaces. Modifications: Perform instance exact matches and/or class type check vs common used types, while exposing unstable APIs to allow users to do the same, if necessary. Result: Better performance of Http pipeline with/without websocket handler. Fixes netty#13261
759d587
to
6a4645b
Compare
6a4645b
to
93d6a3e
Compare
microbench/src/main/java/io/netty/microbench/http/HttpRequestResponseBenchmark.java
Dismissed
Show dismissed
Hide dismissed
.../java/io/netty/handler/codec/http/websocketx/extensions/WebSocketServerExtensionHandler.java
Outdated
Show resolved
Hide resolved
.../java/io/netty/handler/codec/http/websocketx/extensions/WebSocketServerExtensionHandler.java
Outdated
Show resolved
Hide resolved
Done @chrisvest let me know if the code paths I've commented myself seems ok to you |
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... just 3 nits
microbench/src/main/java/io/netty/microbench/http/HttpRequestResponseBenchmark.java
Show resolved
Hide resolved
microbench/src/main/java/io/netty/microbench/http/HttpRequestResponseBenchmark.java
Show resolved
Hide resolved
codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseEncoder.java
Outdated
Show resolved
Hide resolved
7200625
to
371bd2d
Compare
371bd2d
to
e3fba81
Compare
@normanmaurer @trustin added the comments as requested:sorry for the delay and the bad coding :"( |
@chrisvest addressed all the comments: I'm still quite unhappy about the changes, but I have no other solution to the slow path problem |
@franz1981 Thanks! Do you have plans for making similar PRs for Netty 5? I assume the type profiles will have to be looked at again to see what checks are potential hot spots. |
Motivation:
Http encoders/decoders and websocket handlers perform slow type checks
i.e. O(N) search among all implemented interfaces for non-implemented interfaces.
Modifications:
Perform instance exact matches and/or class type check vs common used types, while exposing
unstable APIs to allow users to do the same, if necessary.
Result:
Better performance of Http pipeline with/without websocket handler.
Fixes #13261