-
Notifications
You must be signed in to change notification settings - Fork 2.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
RESTEasy http performance #5220
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.function.Supplier; | ||
|
||
import javax.enterprise.inject.Instance; | ||
import javax.enterprise.inject.spi.CDI; | ||
|
@@ -96,12 +97,16 @@ private void dispatch(RoutingContext routingContext, InputStream is, VertxOutput | |
HttpServerResponse response = request.response(); | ||
VertxHttpResponse vertxResponse = new VertxHttpResponse(request, dispatcher.getProviderFactory(), | ||
request.method(), allocator, output); | ||
// client address may not be available with VirtualHttp | ||
SocketAddress socketAddress = request.remoteAddress(); | ||
String host = socketAddress != null ? socketAddress.host() : null; | ||
// client address may not be available with VirtualHttp; | ||
// using a supplier to make the remote Address resolution lazy: often it's not needed. | ||
Supplier<String> hostNameProvider = () -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We try and avoid lambdas in the runtime part of the code as they are much more costly in terms of metaspsace than an anonymous class. If this is expensive shouldn't the result of this be cached either in the Supplier or in VertxHttpRequest in case getRemoteAddress is called multiple times? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok I can change the lambda to an anonymous class. I know the metaspace cost, TBH I gave up on avoiding them in runtime code as we have many of them anyway, I had the impression nobody except me was still following that recommendation :) It's not clear to me if it's worth caching the result. I can do that "just in case", but FYI the getter is not invoked during hot-path code in the benchmarks I've run: I verified this by initially running a modified version which was throing an exception. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P.S. the reason I ask if it's worth caching, is because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe don't bother then, it is probably not a big deal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Sanne Just for the record, you're not the only one avoiding lambdas in runtime code. We have some in build time but we really try to be careful for the runtime part. But certainly some have slipped along the way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can confirm what @gsmet mentions from my part as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean there's plenty in the libraries we use - even if we avoid them in But I agree with the principle of not opting for a lambda without a strong reason, I'll be more careful. Thanks! |
||
SocketAddress socketAddress = request.remoteAddress(); | ||
String host = socketAddress != null ? socketAddress.host() : null; | ||
return host; | ||
}; | ||
|
||
VertxHttpRequest vertxRequest = new VertxHttpRequest(ctx, headers, uriInfo, request.rawMethod(), | ||
host, dispatcher.getDispatcher(), vertxResponse, false); | ||
VertxHttpRequest vertxRequest = new VertxHttpRequest(ctx, headers, uriInfo, request.rawMethod(), hostNameProvider, | ||
dispatcher.getDispatcher(), vertxResponse); | ||
vertxRequest.setInputStream(is); | ||
try { | ||
ResteasyContext.pushContext(SecurityContext.class, new QuarkusResteasySecurityContext(request)); | ||
|
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.
@stuartwdouglas just to be sure that this shouldn't have been consumed somehow?