From 3e94c1d890864992935ac9c3e6a4901a052c4977 Mon Sep 17 00:00:00 2001 From: stanbot8 Date: Thu, 5 Mar 2026 10:24:14 +0000 Subject: [PATCH] Skip UpdateStaticness per-agent work when detect_static_agents is false UpdateStaticnessOp called Simulation::GetActive()->GetParam() and wrote two booleans for every agent every step, even when detect_static_agents was false (the default). Both values are already initialized to false, so the writes were redundant. Cache the flag once per step in SetUp and return immediately from the per-agent call when the feature is disabled. --- src/core/operation/default_ops.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/operation/default_ops.cc b/src/core/operation/default_ops.cc index e23fc7e2e..1840e82ea 100644 --- a/src/core/operation/default_ops.cc +++ b/src/core/operation/default_ops.cc @@ -48,7 +48,18 @@ BDM_REGISTER_OP(MechanicalForcesOpOpenCL, "mechanical forces", kOpenCl); struct UpdateStaticnessOp : public AgentOperationImpl { BDM_OP_HEADER(UpdateStaticnessOp); - void operator()(Agent* agent) override { agent->UpdateStaticness(); } + void SetUp() override { + detect_static_ = Simulation::GetActive()->GetParam()->detect_static_agents; + } + + void operator()(Agent* agent) override { + if (!detect_static_) { + return; + } + agent->UpdateStaticness(); + } + + bool detect_static_ = false; }; BDM_REGISTER_OP(UpdateStaticnessOp, "update staticness", kCpu);