Skip to content

[core][1/N] Avoid unnecessary deserialization/serialization of TaskId#53577

Merged
edoakes merged 2 commits intoray-project:masterfrom
kevin85421:laptop-ray2-20250604
Jun 9, 2025
Merged

[core][1/N] Avoid unnecessary deserialization/serialization of TaskId#53577
edoakes merged 2 commits intoray-project:masterfrom
kevin85421:laptop-ray2-20250604

Conversation

@kevin85421
Copy link
Copy Markdown
Member

@kevin85421 kevin85421 commented Jun 5, 2025

Why are these changes needed?

task_spec.TaskId().Binary()
  • TaskId() deserializes binary to TaskId.
  • Binary() serializes TaskId to binary.

This PR:

  • renames TaskId to GetTaskId
  • adds GetTaskIdBinary

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@kevin85421 kevin85421 added the go add ONLY when ready to merge, run all tests label Jun 5, 2025
@kevin85421 kevin85421 marked this pull request as ready for review June 5, 2025 17:33
Copilot AI review requested due to automatic review settings June 5, 2025 17:33
@kevin85421 kevin85421 requested a review from a team as a code owner June 5, 2025 17:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new GetTaskIdBinary() method on TaskSpecification to avoid unnecessary deserialization (TaskId()) followed by re-serialization (Binary()), and replaces existing callsites accordingly.

  • Added TaskSpecification::GetTaskIdBinary() to return the raw binary task ID (or a nil ID if unset).
  • Updated RPC serializers and submitter logic to use GetTaskIdBinary() instead of TaskId().Binary().
  • Adjusted unit tests to expect GetTaskIdBinary() in place of TaskId().Binary().

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/ray/common/task/task_spec.h Declares GetTaskIdBinary() on TaskSpecification.
src/ray/common/task/task_spec.cc Implements GetTaskIdBinary().
src/ray/gcs/pb_util.h Uses GetTaskIdBinary() in FillTaskInfo overloads.
src/ray/core_worker/transport/normal_task_submitter.cc Replaces TaskId().Binary() with GetTaskIdBinary().
src/ray/core_worker/transport/actor_task_submitter.cc Same replacement in actor submitter.
src/ray/core_worker/task_manager.cc Uses new method in stats filling.
src/ray/core_worker/core_worker.cc Updates running task ID serialization.
src/ray/core_worker/test/normal_task_submitter_test.cc Updates expectations in kill-task tests.
src/ray/core_worker/test/actor_task_submitter_test.cc Updates retries in actor task test.
Comments suppressed due to low confidence (3)

src/ray/common/task/task_spec.h:296

  • Consider adding dedicated unit tests for GetTaskIdBinary(), covering both the non-empty and empty (nil) cases to ensure it returns the expected binary string.
std::string GetTaskIdBinary() const;

src/ray/common/task/task_spec.h:296

  • [nitpick] The comment for GetTaskIdBinary() could note that this method bypasses deserialization, highlighting its performance benefit and intended use over TaskId().Binary().
std::string GetTaskIdBinary() const;

src/ray/common/task/task_spec.h:296

  • [nitpick] This accessor is small and called frequently—marking it inline in the header could avoid an out-of-line call and improve performance in hot paths.
std::string GetTaskIdBinary() const;

Copy link
Copy Markdown
Collaborator

@edoakes edoakes Jun 5, 2025

Choose a reason for hiding this comment

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

same as other PR -- the existing method is TaskId, not GetTaskId. keep naming consistent.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Update TaskId to GetTaskId to keep naming consistent #53574 (comment).

If you prefer TaskId to GetTaskId, feel free to let me know.

Copy link
Copy Markdown
Collaborator

@edoakes edoakes Jun 9, 2025

Choose a reason for hiding this comment

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

GetTaskId sounds better to me

Though now we have more inconsistency because half of the TaskSpecification getters start with Get and half don't :)

Can you follow up in a separate PR to update all of them?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Double checked in the Google C++ style and there is no explicit mention of this, but they indicate that getters/setters can be named with snake_case like variable names and in the example they give, there is no get or Get prefix.

I don't have a strong opinion here because I am not a C++ expert. @dayshah is there a standard idiom we should be following?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

they indicate that getters/setters can be named with snake_case like variable names and in the example they give, there is no get or Get prefix.

How about we keep using TaskId and rename GetTaskIdBinary to TaskIdBinary? I can remove the prefix Get from GetArgObjectId and GetArgObjectIdBinary to keep the consistency.

The Get prefix doesn’t affect readability for me.

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.

ya usually you don't want the Get prefix. norm is a getter/setter with the same name one is const, one is non const

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

sounds good @kevin85421

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Kai-Hsun Chen <kaihsun@anyscale.com>
Signed-off-by: Kai-Hsun Chen <kaihsun@anyscale.com>
@kevin85421 kevin85421 force-pushed the laptop-ray2-20250604 branch from 4d12675 to 8dbb0ee Compare June 9, 2025 17:28
@kevin85421 kevin85421 requested a review from edoakes June 9, 2025 20:10
@edoakes edoakes merged commit 7fa8f44 into ray-project:master Jun 9, 2025
5 checks passed
elliot-barn pushed a commit that referenced this pull request Jun 18, 2025
…#53577)

```cpp
task_spec.TaskId().Binary()
```
* `TaskId()` deserializes binary to TaskId.
* `Binary()` serializes `TaskId` to binary.

This PR:
* renames `TaskId` to `GetTaskId`
* adds `GetTaskIdBinary`

---------

Signed-off-by: Kai-Hsun Chen <kaihsun@anyscale.com>
Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
elliot-barn pushed a commit that referenced this pull request Jul 2, 2025
…#53577)

```cpp
task_spec.TaskId().Binary()
```
* `TaskId()` deserializes binary to TaskId.
* `Binary()` serializes `TaskId` to binary.

This PR:
* renames `TaskId` to `GetTaskId`
* adds `GetTaskIdBinary`

---------

Signed-off-by: Kai-Hsun Chen <kaihsun@anyscale.com>
Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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