Skip to content

Commit 964a856

Browse files
committed
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.
1 parent b8aa228 commit 964a856

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/core/operation/default_ops.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,18 @@ BDM_REGISTER_OP(MechanicalForcesOpOpenCL, "mechanical forces", kOpenCl);
4848
struct UpdateStaticnessOp : public AgentOperationImpl {
4949
BDM_OP_HEADER(UpdateStaticnessOp);
5050

51-
void operator()(Agent* agent) override { agent->UpdateStaticness(); }
51+
void SetUp() override {
52+
detect_static_ = Simulation::GetActive()->GetParam()->detect_static_agents;
53+
}
54+
55+
void operator()(Agent* agent) override {
56+
if (!detect_static_) {
57+
return;
58+
}
59+
agent->UpdateStaticness();
60+
}
61+
62+
bool detect_static_ = false;
5263
};
5364

5465
BDM_REGISTER_OP(UpdateStaticnessOp, "update staticness", kCpu);

0 commit comments

Comments
 (0)