perf: 将 poll_points 改为 Arc<Vec<PollPointInfo>> 以减少 clone 开销
This commit is contained in:
parent
487d3cdf26
commit
a2208e8958
|
|
@ -95,7 +95,7 @@ pub struct ConnectionStatus {
|
|||
pub next_client_handle: u32,
|
||||
pub client_handle_map: HashMap<u32, Uuid>, // client_handle -> point_id
|
||||
pub monitored_item_map: HashMap<Uuid, u32>, // point_id -> monitored_item_id
|
||||
pub poll_points: Vec<PollPointInfo>, // 正在轮询的点集合
|
||||
pub poll_points: Arc<Vec<PollPointInfo>>, // 正在轮询的点集合
|
||||
poll_handle: Option<JoinHandle<()>>, // 统一的轮询任务句柄
|
||||
heartbeat_handle: Option<JoinHandle<()>>, // 心跳任务句柄
|
||||
}
|
||||
|
|
@ -370,7 +370,7 @@ impl ConnectionManager {
|
|||
let poll_points = {
|
||||
let status = status_ref.read().await;
|
||||
status.get(&source_id)
|
||||
.map(|conn_status| conn_status.poll_points.clone())
|
||||
.map(|conn_status| Arc::clone(&conn_status.poll_points))
|
||||
.unwrap_or_default()
|
||||
};
|
||||
|
||||
|
|
@ -458,7 +458,7 @@ impl ConnectionManager {
|
|||
for point in points {
|
||||
// 检查点是否已经在轮询列表中
|
||||
if !conn_status.poll_points.iter().any(|p| p.point_id == point.point_id) {
|
||||
conn_status.poll_points.push(PollPointInfo {
|
||||
Arc::make_mut(&mut conn_status.poll_points).push(PollPointInfo {
|
||||
point_id: point.point_id,
|
||||
external_id: point.external_id.clone(),
|
||||
});
|
||||
|
|
@ -592,7 +592,7 @@ impl ConnectionManager {
|
|||
next_client_handle: 1000,
|
||||
client_handle_map: HashMap::new(),
|
||||
monitored_item_map: HashMap::new(),
|
||||
poll_points: Vec::new(),
|
||||
poll_points: Arc::new(Vec::new()),
|
||||
poll_handle: None,
|
||||
heartbeat_handle: None,
|
||||
},
|
||||
|
|
@ -622,7 +622,7 @@ impl ConnectionManager {
|
|||
client_handle_map: HashMap::new(),
|
||||
monitored_item_map: HashMap::new(),
|
||||
next_client_handle: 1000,
|
||||
poll_points: Vec::new(),
|
||||
poll_points: Arc::new(Vec::new()),
|
||||
poll_handle: None,
|
||||
heartbeat_handle: None,
|
||||
},
|
||||
|
|
@ -653,7 +653,7 @@ impl ConnectionManager {
|
|||
{
|
||||
let mut status = self.status.write().await;
|
||||
if let Some(conn_status) = status.get_mut(&source_id) {
|
||||
conn_status.poll_points.clear();
|
||||
Arc::make_mut(&mut conn_status.poll_points).clear();
|
||||
if let Some(handle) = conn_status.poll_handle.take() {
|
||||
handle.abort();
|
||||
}
|
||||
|
|
@ -685,7 +685,7 @@ impl ConnectionManager {
|
|||
{
|
||||
let mut status = self.status.write().await;
|
||||
if let Some(conn_status) = status.get_mut(&source_id) {
|
||||
conn_status.poll_points.clear();
|
||||
Arc::make_mut(&mut conn_status.poll_points).clear();
|
||||
if let Some(handle) = conn_status.poll_handle.take() {
|
||||
handle.abort();
|
||||
}
|
||||
|
|
@ -1154,7 +1154,7 @@ impl ConnectionManager {
|
|||
.monitored_item_map
|
||||
.insert(point.point_id, monitored_item_result.result.monitored_item_id);
|
||||
// 从轮询列表中移除该点
|
||||
conn_status.poll_points.retain(|p| p.point_id != point.point_id);
|
||||
Arc::make_mut(&mut conn_status.poll_points).retain(|p| p.point_id != point.point_id);
|
||||
}
|
||||
} else {
|
||||
tracing::error!(
|
||||
|
|
@ -1302,7 +1302,7 @@ impl ConnectionManager {
|
|||
let mut status = self.status.write().await;
|
||||
if let Some(conn_status) = status.get_mut(&source_id) {
|
||||
let before_count = conn_status.poll_points.len();
|
||||
conn_status.poll_points.retain(|p| !target_ids.contains(&p.point_id));
|
||||
Arc::make_mut(&mut conn_status.poll_points).retain(|p| !target_ids.contains(&p.point_id));
|
||||
let after_count = conn_status.poll_points.len();
|
||||
before_count - after_count
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue