Skip to content

Commit e422d0a

Browse files
homa31claude
andcommitted
Make DistributedTaskContext Copy
It's two usize fields with no heap data, so Copy is a free refinement over Clone. Drop the now-redundant `.clone()` calls at internal sites that pass it by value (recursion helpers, worker metrics callbacks). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent a9e0df3 commit e422d0a

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/common/recursion.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,19 @@ impl TreeNodeExt for Arc<dyn ExecutionPlan> {
8585
ctx: DistributedTaskContext,
8686
f: &mut F,
8787
) -> Result<TreeNodeRecursion> {
88-
f(plan, ctx.clone())?.visit_children(|| {
88+
f(plan, ctx)?.visit_children(|| {
8989
if let Some(ciu) = plan.as_any().downcast_ref::<ChildrenIsolatorUnionExec>() {
9090
// Just recurse to children that will actually get executed by this
9191
// ChildrenIsolatorUnionExec.
9292
ciu.task_idx_map[ctx.task_index].iter().apply_until_stop(
93-
|(child_i, child_ctx)| {
94-
recurse(&ciu.children[*child_i], child_ctx.clone(), f)
95-
},
93+
|(child_i, child_ctx)| recurse(&ciu.children[*child_i], *child_ctx, f),
9694
)
9795
} else if plan.is_network_boundary() {
9896
Ok(TreeNodeRecursion::Continue)
9997
} else {
10098
plan.children()
10199
.into_iter()
102-
.apply_until_stop(|child| recurse(child, ctx.clone(), f))
100+
.apply_until_stop(|child| recurse(child, ctx, f))
103101
}
104102
})
105103
}
@@ -126,7 +124,7 @@ impl TreeNodeExt for Arc<dyn ExecutionPlan> {
126124
tnr: TreeNodeRecursion::Jump,
127125
});
128126
};
129-
let transformed = f(node, dt_ctx.clone())?;
127+
let transformed = f(node, dt_ctx)?;
130128
if transformed.tnr == TreeNodeRecursion::Stop {
131129
return Ok(transformed);
132130
}
@@ -142,11 +140,11 @@ impl TreeNodeExt for Arc<dyn ExecutionPlan> {
142140
if let Some(ciu) = node.as_any().downcast_ref::<ChildrenIsolatorUnionExec>() {
143141
let mut child_ctxs = vec![None; ciu.children.len()];
144142
for (child_idx, child_ctx) in &ciu.task_idx_map[dt_ctx.task_index] {
145-
child_ctxs[*child_idx] = Some(child_ctx.clone());
143+
child_ctxs[*child_idx] = Some(*child_ctx);
146144
}
147145
stack.extend(child_ctxs.into_iter().rev());
148146
} else {
149-
stack.extend(node.children().iter().map(|_| Some(dt_ctx.clone())).rev());
147+
stack.extend(node.children().iter().map(|_| Some(dt_ctx)).rev());
150148
}
151149
Ok(transformed)
152150
})

src/stage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Stage {
139139
}
140140
}
141141

142-
#[derive(Debug, Clone, PartialEq)]
142+
#[derive(Debug, Clone, Copy, PartialEq)]
143143
pub struct DistributedTaskContext {
144144
pub task_index: usize,
145145
pub task_count: usize,

src/worker/impl_execute_task.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(crate) async fn execute_local_task(
6464
let plan = task_data.plan;
6565
let task_ctx = task_data.task_ctx;
6666
let d_cfg = DistributedConfig::from_config_options(task_ctx.session_config().options())?;
67-
let d_ctx = DistributedTaskContext::from_ctx(&task_ctx).as_ref().clone();
67+
let d_ctx = *DistributedTaskContext::from_ctx(&task_ctx).as_ref();
6868

6969
let send_metrics = d_cfg.collect_metrics;
7070
let partition_count = plan.properties().partitioning.partition_count();
@@ -91,7 +91,6 @@ pub(crate) async fn execute_local_task(
9191
let metrics_tx = Arc::clone(&task_data.metrics_tx);
9292
let task_data_metrics = Arc::clone(&task_data.task_data_metrics);
9393
let key = key.clone();
94-
let d_ctx = d_ctx.clone();
9594
let stream = on_drop_stream(stream, move || {
9695
// Stream was dropped before fully consumed -- see https://github.com/datafusion-contrib/datafusion-distributed/issues/412
9796
// Send metrics via the coordinator channel so they are not lost.

0 commit comments

Comments
 (0)