From 6a343bf327ae0050b8e396c26a42806f141f21e3 Mon Sep 17 00:00:00 2001 From: eduardgushchin Date: Wed, 30 Sep 2026 13:10:21 +0300 Subject: [PATCH 1/2] perf: avoid static revolute state allocations --- src/Box2D.NET/B2RevoluteJoints.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Box2D.NET/B2RevoluteJoints.cs b/src/Box2D.NET/B2RevoluteJoints.cs index e5b0a7bf..17be1d84 100644 --- a/src/Box2D.NET/B2RevoluteJoints.cs +++ b/src/Box2D.NET/B2RevoluteJoints.cs @@ -282,8 +282,8 @@ internal static void b2WarmStartRevoluteJoint(B2JointSim @base, B2StepContext co float iA = @base.invIA; float iB = @base.invIB; - // dummy state for static bodies - B2BodyState dummyState = B2BodyState.Create(b2_identityBodyState); + // Static-body branches only read this shared identity state. + B2BodyState dummyState = b2_identityBodyState; ref readonly B2RevoluteJoint joint = ref @base.uj.revoluteJoint; B2BodyState stateA = joint.indexA == B2_NULL_INDEX ? dummyState : context.states[joint.indexA]; @@ -316,8 +316,8 @@ internal static void b2SolveRevoluteJoint(B2JointSim @base, B2StepContext contex float iA = @base.invIA; float iB = @base.invIB; - // dummy state for static bodies - B2BodyState dummyState = B2BodyState.Create(b2_identityBodyState); + // Static-body branches only read this shared identity state. + B2BodyState dummyState = b2_identityBodyState; ref B2RevoluteJoint joint = ref @base.uj.revoluteJoint; From d8cde1fbd96dab08093afac6a5a0df32d974dd7f Mon Sep 17 00:00:00 2001 From: eduardgushchin Date: Wed, 30 Sep 2026 14:11:30 +0300 Subject: [PATCH 2/2] perf: avoid static wheel state allocations --- src/Box2D.NET/B2WheelJoints.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Box2D.NET/B2WheelJoints.cs b/src/Box2D.NET/B2WheelJoints.cs index 64033ada..d172cc7c 100644 --- a/src/Box2D.NET/B2WheelJoints.cs +++ b/src/Box2D.NET/B2WheelJoints.cs @@ -277,8 +277,8 @@ internal static void b2WarmStartWheelJoint(B2JointSim @base, B2StepContext conte float iA = @base.invIA; float iB = @base.invIB; - // dummy state for static bodies - B2BodyState dummyState = B2BodyState.Create(b2_identityBodyState); + // Static-body branches only read this shared identity state. + B2BodyState dummyState = b2_identityBodyState; ref readonly B2WheelJoint joint = ref @base.uj.wheelJoint; @@ -326,8 +326,8 @@ internal static void b2SolveWheelJoint(B2JointSim @base, B2StepContext context, float iA = @base.invIA; float iB = @base.invIB; - // dummy state for static bodies - B2BodyState dummyState = B2BodyState.Create(b2_identityBodyState); + // Static-body branches only read this shared identity state. + B2BodyState dummyState = b2_identityBodyState; ref B2WheelJoint joint = ref @base.uj.wheelJoint;