-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[Core] Replace read-only string parameters with string_view on critical path #59915
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: tianyi-ge <tianyig@outlook.com>
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.
Code Review
This pull request replaces const std::string& with std::string_view for read-only string parameters on performance-critical paths. This is a good optimization to avoid unnecessary string allocations. The changes are applied consistently across several core worker components. My review includes suggestions to further optimize the use of std::string_view with protobuf setters to prevent the creation of temporary std::string objects, thereby fully realizing the performance benefits of this change.
| TaskSpecBuilder &SetCommonTaskSpec( | ||
| const TaskID &task_id, | ||
| const std::string name, | ||
| std::string_view name, |
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.
| std::string_view debugger_breakpoint, | ||
| int64_t depth, | ||
| const TaskID &submitter_task_id, | ||
| const std::string &call_site, | ||
| std::string_view call_site, | ||
| const std::shared_ptr<rpc::RuntimeEnvInfo> runtime_env_info = nullptr, | ||
| const std::string &concurrency_group_name = "", | ||
| std::string_view concurrency_group_name = "", |
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.
To fully leverage std::string_view and avoid temporary std::string allocations, please use the (const char*, size_t) overload for the protobuf setters in this function's body. For example: message_->set_debugger_breakpoint(debugger_breakpoint.data(), debugger_breakpoint.size());. This applies to call_site and concurrency_group_name as well.
| int max_retries, | ||
| bool retry_exceptions, | ||
| const std::string &serialized_retry_exception_allowlist, | ||
| std::string_view serialized_retry_exception_allowlist, |
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.
| TaskSpecBuilder &SetActorCreationTaskSpec( | ||
| const ActorID &actor_id, | ||
| const std::string &serialized_actor_handle, | ||
| std::string_view serialized_actor_handle, |
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.
| bool is_asyncio = false, | ||
| const std::vector<ConcurrencyGroup> &concurrency_groups = {}, | ||
| const std::string &extension_data = "", | ||
| std::string_view extension_data = "", |
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.
| const ObjectID &actor_creation_dummy_object_id, | ||
| int max_retries, | ||
| bool retry_exceptions, | ||
| std::string_view serialized_retry_exception_allowlist, |
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.
| std::string_view extension_data, | ||
| int64_t max_task_retries, | ||
| const std::string &name, | ||
| const std::string &ray_namespace, | ||
| std::string_view name, | ||
| std::string_view ray_namespace, |
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.
To fully leverage std::string_view and avoid temporary std::string allocations, please use the (const char*, size_t) overload for the protobuf setters in this function's body. For example, inner.set_extension_data(extension_data.data(), extension_data.size());. This applies to name and ray_namespace as well.
| std::string_view stdout_path, | ||
| std::string_view stderr_path, |
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.
edoakes
left a comment
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.
@israbbani @dayshah PTAL
|
@tianyi-ge. Thanks for the contribution. I've started some discussion on the original issue. #59887. I'll hold off on reviewing this until we finish the discussion there. |
Description
Replace
const std::string &withstd::string_viewto avoid temporary string for a string literal or substringRelated issues
Closes #59887
Additional information
protobuf
ParseFromStringonly accepts std::string.ray/src/ray/core_worker/actor_handle.cc
Lines 64 to 68 in c49b666