Skip to content

perf(native): Fix unnecessary copy in http module#27063

Merged
amitkdutta merged 1 commit intoprestodb:masterfrom
amitkdutta:export-D91994719
Feb 3, 2026
Merged

perf(native): Fix unnecessary copy in http module#27063
amitkdutta merged 1 commit intoprestodb:masterfrom
amitkdutta:export-D91994719

Conversation

@amitkdutta
Copy link
Copy Markdown
Contributor

@amitkdutta amitkdutta commented Feb 1, 2026

Summary:
Fix unnecessary copies in the Presto HTTP module:

  • Use std::move() for shared_ptr, SSLContextPtr, and callback assignments
  • Use const reference for path variable to avoid copy from getPath()

These changes eliminate unnecessary copy operations and improve performance.

== NO RELEASE NOTE ==

Summary by Sourcery

Address performance-related cleanups in the Presto HTTP client and server by eliminating unnecessary copies of objects and strings.

Enhancements:

  • Move HTTP client and server callbacks, timers, and context objects instead of copying to avoid redundant allocations and ownership transfers.
  • Bind the HTTP request path as a const reference rather than copying the string when dispatching request handlers.

@amitkdutta amitkdutta requested review from a team as code owners February 1, 2026 07:44
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Feb 1, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Feb 1, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors parts of the Presto HTTP client and server to eliminate unnecessary copies by moving ownership where appropriate and binding to const references instead of making temporary copies, primarily to satisfy INFERMINICPP lint warnings and improve performance.

Class diagram for updated HTTP client and server move semantics

classDiagram
  class HttpClient {
    +HttpClient(std__string host, uint16_t port, std__shared_ptr~proxygen__HTTPConnector~ pool, folly__SSLContextPtr sslContext, std__function~void(HttpStats&)~ reportOnBodyStatsFunc)
    -std__shared_ptr~proxygen__HTTPConnector~ pool_
    -folly__SSLContextPtr sslContext_
    -std__function~void(HttpStats&)~ reportOnBodyStatsFunc_
  }

  class ResponseHandler {
    +folly__SemiFuture~std__unique_ptr~HttpResponse~~ initialize(std__shared_ptr~ResponseHandler~ self)
    -std__shared_ptr~ResponseHandler~ self_
    -folly__Promise~std__unique_ptr~HttpResponse~~ promise_
  }

  class ConnectionHandler {
    +ConnectionHandler(std__shared_ptr~ResponseHandler~ responseHandler, std__shared_ptr~SessionPool~ sessionPool, std__chrono__milliseconds transactionTimeout, std__chrono__milliseconds connectTimeout, bool http2Enabled, uint32_t maxConcurrentStreams, folly__SSLContextPtr sslContext)
    -std__shared_ptr~ResponseHandler~ responseHandler_
    -std__shared_ptr~SessionPool~ sessionPool_
    -folly__HHWheelTimer__UniquePtr transactionTimer_
    -std__chrono__milliseconds connectTimeout_
    -bool http2Enabled_
    -uint32_t maxConcurrentStreams_
  }

  class CallbackRequestHandlerState {
    +static std__shared_ptr~CallbackRequestHandlerState~ create()
    +void runOnFinalization(std__function~void(void)~ callback)
    -std__function~void(void)~ onFinalizationCallback_
  }

  class CallbackRequestHandler {
    +CallbackRequestHandler(RequestHandlerCallback callback)
    +CallbackRequestHandler(AsyncRequestHandlerCallback callback)
    -RequestHandlerCallback callback_
    -std__shared_ptr~CallbackRequestHandlerState~ state_
    -static RequestHandlerCallback wrap(RequestHandlerCallback callback)
  }

  class DispatchingRequestHandlerFactory {
    +proxygen__RequestHandler* onRequest(proxygen__RequestHandler* request, proxygen__HTTPMessage* message)
  }

  HttpClient --> ResponseHandler
  ResponseHandler --> ConnectionHandler
  ConnectionHandler --> HttpClient
  CallbackRequestHandler --> CallbackRequestHandlerState
  DispatchingRequestHandlerFactory --> CallbackRequestHandler
  DispatchingRequestHandlerFactory --> HttpClient
Loading

File-Level Changes

Change Details Files
Avoid unnecessary copies by moving pointer-like and callable objects instead of copying them.
  • Move the sslContext constructor argument into the HttpClient::sslContext_ member instead of copying it.
  • Move the self shared_ptr into ResponseHandler::self_ during initialization to avoid an extra shared_ptr copy.
  • Move the transactionTimeout argument into ConnectionHandler::transactionTimer_ instead of copying it.
  • Move the std::function callback passed to CallbackRequestHandlerState::runOnFinalization into onFinalizationCallback_.
  • Move the RequestHandlerCallback and AsyncRequestHandlerCallback into the CallbackRequestHandler::callback_ member instead of copying them, and still wrap the moved RequestHandlerCallback.
presto-native-execution/presto_cpp/main/http/HttpClient.cpp
presto-native-execution/presto_cpp/main/http/HttpServer.h
Avoid string copies when accessing HTTP request paths.
  • Bind the result of message->getPath() to a const reference instead of creating a new string copy in DispatchingRequestHandlerFactory::onRequest.
presto-native-execution/presto_cpp/main/http/HttpServer.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

amitkdutta added a commit to amitkdutta/presto that referenced this pull request Feb 1, 2026
Summary:

Fix INFERMINICPP lint warnings for unnecessary copies in the Presto HTTP module:
- Use std::move() for shared_ptr, SSLContextPtr, and callback assignments
- Use const reference for path variable to avoid copy from getPath()

These changes eliminate unnecessary copy operations and improve performance.

Differential Revision: D91994719
amitkdutta added a commit to amitkdutta/presto that referenced this pull request Feb 1, 2026
Summary:

Fix INFERMINICPP lint warnings for unnecessary copies in the Presto HTTP module:
- Use std::move() for shared_ptr, SSLContextPtr, and callback assignments
- Use const reference for path variable to avoid copy from getPath()

These changes eliminate unnecessary copy operations and improve performance.

Differential Revision: D91994719
@amitkdutta amitkdutta changed the title misc: Fix unnecessary copy lint warnings in http module misc: Fix unnecessary copy in http module Feb 1, 2026
amitkdutta added a commit to amitkdutta/presto that referenced this pull request Feb 1, 2026
Summary:

Fix INFERMINICPP lint warnings for unnecessary copies in the Presto HTTP module:
- Use std::move() for shared_ptr, SSLContextPtr, and callback assignments
- Use const reference for path variable to avoid copy from getPath()

These changes eliminate unnecessary copy operations and improve performance.

Differential Revision: D91994719
Copy link
Copy Markdown
Contributor

@PingLiuPing PingLiuPing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amitkdutta

@amitkdutta amitkdutta changed the title misc: Fix unnecessary copy in http module misc(perf): Fix unnecessary copy in http module Feb 1, 2026
@amitkdutta amitkdutta changed the title misc(perf): Fix unnecessary copy in http module misc: Fix unnecessary copy in http module Feb 2, 2026
@amitkdutta amitkdutta changed the title misc: Fix unnecessary copy in http module perf(native): Fix unnecessary copy in http module Feb 2, 2026
amitkdutta added a commit to amitkdutta/presto that referenced this pull request Feb 2, 2026
Summary:

Fix INFERMINICPP lint warnings for unnecessary copies in the Presto HTTP module:
- Use std::move() for shared_ptr, SSLContextPtr, and callback assignments
- Use const reference for path variable to avoid copy from getPath()

These changes eliminate unnecessary copy operations and improve performance.

Differential Revision: D91994719
Summary:

Fix INFERMINICPP lint warnings for unnecessary copies in the Presto HTTP module:
- Use std::move() for shared_ptr, SSLContextPtr, and callback assignments
- Use const reference for path variable to avoid copy from getPath()

These changes eliminate unnecessary copy operations and improve performance.

Differential Revision: D91994719
Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amitkdutta

@amitkdutta amitkdutta merged commit 6b9cb83 into prestodb:master Feb 3, 2026
100 of 121 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants