Room for performance improvement in MyPhysicsBody.RigidBody

Guest shared this bug 2 years ago
Reported

Game version: 1.200.030

The getter of the MyPhysicsBody.RigidBody property has redundant code:

get => this.WeldInfo.Parent == null ? this.m_rigidBody : this.WeldInfo.Parent.RigidBody;

Based on dotTrace profiling results it consumes 0.8% of Main thread CPU load on big multiplayer servers, have seen it on two so far. It is not much, but it may be a low hanging fruit to save a bit of CPU power.

Please check out the IL code generated (screenshot attached). It has the relatively expensive variable lookup twice. Unfortunately the compiler did not optimize it out and the JIT may not be clever enough either. (I haven't checked the generated machine code, however.)

Maybe a rewrite like this would be slightly more performant:

get => WeldInfo.Parent?.RigidBody ?? m_rigidBody;

Replies (1)

photo
1

Hello, Viktor,

thanks for letting us know. Issue was reported internally.

Kind Regards

Keen Software House: QA Department

Leave a Comment
 
Attach a file