Skip to content

[core] Remove extra copy through proxy on every worker server request - #59245

Merged
jjyao merged 1 commit into
ray-project:masterfrom
dayshah:remove-copy-worker-rpc
Dec 8, 2025
Merged

jjyao merged 1 commit into
ray-project:masterfrom
dayshah:remove-copy-worker-rpc

Conversation

@dayshah

@dayshah dayshah commented Dec 7, 2025 •

Copy link
Copy Markdown
Contributor

Description

Found that there's an extra unnecessary copy on every worker request through the CoreWorkerServiceHandlerProxy. This ends up dominating io context time in cases where you're streaming back lots of large objects (tested through config var to bump up max inline size).

Screenshot 2025-12-07 at 2 05 03 PM

@dayshah
dayshah requested a review from a team as a code owner December 7, 2025 22:04
@dayshah dayshah added the go add ONLY when ready to merge, run all tests label Dec 7, 2025

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a performance optimization in the CoreWorkerServiceHandlerProxy by using std::move to forward requests and callbacks. This avoids unnecessary copies for every worker server request, which is particularly beneficial when dealing with large objects. The change is correct, well-contained within a macro, and the inclusion of the <utility> header is appropriate. I find no issues with this change.

@Yicheng-Lu-llll

Copy link
Copy Markdown
Member

LGTM! Adding a bit more context for reviewers:

Ideally, the io_context thread would call CoreWorker methods directly. But due to the startup ordering issue described here:

// This class was introduced as a result of changes in
// https://github.com/ray-project/ray/pull/54759, where the dependencies of CoreWorker
// were refactored into CoreWorkerProcessImpl. Previously, CoreWorker inherited from
// CoreWorkerServiceHandler, but this design made it impossible to run the gRPC server
// within CoreWorkerProcessImpl despite the fact that several CoreWorker subclasses rely
// on the server's port, which is only known when the server is running. To address this,
// we created this service handler which can be created before CoreWorker is done
// initializing. This pattern is NOT recommended for future use and was only used
// as other options were significantly more ugly and complex.

every request needs to go through the Proxy first, which then forwards it to CoreWorker.

Since this path is hit for every worker RPC, using std::move here instead of copying makes total sense and can save a lot of time, especially for large requests.

@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Dec 8, 2025
@jjyao
jjyao merged commit 6ac01d3 into ray-project:master Dec 8, 2025
@dayshah
dayshah deleted the remove-copy-worker-rpc branch December 8, 2025 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants