diff --git a/src/common/task.cc b/src/common/task.cc index 9b4969618482..b8de284ede38 100644 --- a/src/common/task.cc +++ b/src/common/task.cc @@ -426,7 +426,7 @@ TaskExecutionSpec::TaskExecutionSpec(TaskExecutionSpec *other) spec_ = std::unique_ptr(spec_copy); } -std::vector TaskExecutionSpec::ExecutionDependencies() const { +const std::vector &TaskExecutionSpec::ExecutionDependencies() const { return execution_dependencies_; } diff --git a/src/common/task.h b/src/common/task.h index e3e2608f8be4..6feffbfe2b85 100644 --- a/src/common/task.h +++ b/src/common/task.h @@ -30,7 +30,7 @@ class TaskExecutionSpec { /// /// @return A vector of object IDs representing this task's execution /// dependencies. - std::vector ExecutionDependencies() const; + const std::vector &ExecutionDependencies() const; /// Set the task's execution dependencies. /// diff --git a/src/ray/object_manager/object_store_notification_manager.cc b/src/ray/object_manager/object_store_notification_manager.cc index 401dbe32ba05..b66e0f4141bd 100644 --- a/src/ray/object_manager/object_store_notification_manager.cc +++ b/src/ray/object_manager/object_store_notification_manager.cc @@ -63,25 +63,25 @@ void ObjectStoreNotificationManager::ProcessStoreNotification( } void ObjectStoreNotificationManager::ProcessStoreAdd(const ObjectInfoT &object_info) { - for (auto handler : add_handlers_) { + for (auto &handler : add_handlers_) { handler(object_info); } } void ObjectStoreNotificationManager::ProcessStoreRemove(const ObjectID &object_id) { - for (auto handler : rem_handlers_) { + for (auto &handler : rem_handlers_) { handler(object_id); } } void ObjectStoreNotificationManager::SubscribeObjAdded( std::function callback) { - add_handlers_.push_back(callback); + add_handlers_.push_back(std::move(callback)); } void ObjectStoreNotificationManager::SubscribeObjDeleted( std::function callback) { - rem_handlers_.push_back(callback); + rem_handlers_.push_back(std::move(callback)); } } // namespace ray diff --git a/src/ray/raylet/node_manager.cc b/src/ray/raylet/node_manager.cc index 5ee3ef6ec15b..d63adb773fea 100644 --- a/src/ray/raylet/node_manager.cc +++ b/src/ray/raylet/node_manager.cc @@ -229,13 +229,14 @@ void NodeManager::HeartbeatAdded(gcs::AsyncGcsClient *client, const ClientID &cl } // Locate the client id in remote client table and update available resources based on // the received heartbeat information. - if (this->cluster_resource_map_.count(client_id) == 0) { + auto it = this->cluster_resource_map_.find(client_id); + if (it == cluster_resource_map_.end()) { // Haven't received the client registration for this client yet, skip this heartbeat. RAY_LOG(INFO) << "[HeartbeatAdded]: received heartbeat from unknown client id " << client_id; return; } - SchedulingResources &resources = this->cluster_resource_map_[client_id]; + SchedulingResources &resources = it->second; ResourceSet heartbeat_resource_available(heartbeat_data.resources_available_label, heartbeat_data.resources_available_capacity); resources.SetAvailableResources( @@ -786,13 +787,14 @@ ray::Status NodeManager::ForwardTask(const Task &task, const ClientID &node_id) auto client_info = gcs_client_->client_table().GetClient(node_id); // Lookup remote server connection for this node_id and use it to send the request. - if (remote_server_connections_.count(node_id) == 0) { + auto it = remote_server_connections_.find(node_id); + if (it == remote_server_connections_.end()) { // TODO(atumanov): caller must handle failure to ensure tasks are not lost. RAY_LOG(INFO) << "No NodeManager connection found for GCS client id " << node_id; return ray::Status::IOError("NodeManager connection not found"); } - auto &server_conn = remote_server_connections_.at(node_id); + auto &server_conn = it->second; auto status = server_conn.WriteMessage(protocol::MessageType_ForwardTaskRequest, fbb.GetSize(), fbb.GetBufferPointer()); if (status.ok()) { diff --git a/src/ray/raylet/scheduling_policy.cc b/src/ray/raylet/scheduling_policy.cc index 4d13fdc4c9bf..1808a5aa284d 100644 --- a/src/ray/raylet/scheduling_policy.cc +++ b/src/ray/raylet/scheduling_policy.cc @@ -45,7 +45,7 @@ std::unordered_map SchedulingPolicy::Schedule( for (const auto &client_resource_pair : cluster_resources) { // pair = ClientID, SchedulingResources ClientID node_client_id = client_resource_pair.first; - SchedulingResources node_resources = client_resource_pair.second; + const auto &node_resources = client_resource_pair.second; RAY_LOG(DEBUG) << "client_id " << node_client_id << " resources: " << node_resources.GetAvailableResources().ToString(); if (resource_demand.IsSubset(node_resources.GetTotalResources())) { diff --git a/src/ray/raylet/scheduling_queue.cc b/src/ray/raylet/scheduling_queue.cc index f8cd9d785766..a1d0a48c1e49 100644 --- a/src/ray/raylet/scheduling_queue.cc +++ b/src/ray/raylet/scheduling_queue.cc @@ -51,10 +51,8 @@ void removeTasksFromQueue(std::list &queue, std::unordered_set &ta } // Helper function to queue the given tasks to the given queue. -void queueTasks(std::list &queue, const std::vector &tasks) { - for (auto &task : tasks) { - queue.push_back(task); - } +inline void queueTasks(std::list &queue, const std::vector &tasks) { + queue.insert(queue.end(), tasks.begin(), tasks.end()); } std::vector SchedulingQueue::RemoveTasks(std::unordered_set task_ids) { diff --git a/src/ray/raylet/worker_pool.cc b/src/ray/raylet/worker_pool.cc index 1a15dd6c22c0..20e34b6cfa5d 100644 --- a/src/ray/raylet/worker_pool.cc +++ b/src/ray/raylet/worker_pool.cc @@ -90,8 +90,9 @@ void WorkerPool::RegisterWorker(std::shared_ptr worker) { auto pid = worker->Pid(); RAY_LOG(DEBUG) << "Registering worker with pid " << pid; registered_workers_.push_back(std::move(worker)); - RAY_CHECK(started_worker_pids_.count(pid) > 0); - started_worker_pids_.erase(pid); + auto it = started_worker_pids_.find(pid); + RAY_CHECK(it != started_worker_pids_.end()); + started_worker_pids_.erase(it); } std::shared_ptr WorkerPool::GetRegisteredWorker(