Developing For Performance: Welds VS CFraming

Throughout my 10 years of developing on Roblox, I’ve done my fair share of testing and performance optimization. One question I get asked a lot, is when to use Welds/Motors vs updating a part’s CFrame periodically.

For starters, there’s some non-performance factors to consider. Welds and Motors rely heavily on Roblox’s Physics engine. This means you can’t use welds on Anchored parts, and parts you weld together will have different physical properties than they would individually. For example, if you weld 10 mid-size parts to your character, they won’t be able to jump as high, because the extra parts have made them heavier. Also Welds automatically update every frame, so you don’t need any additional code to make smooth part movement when using welds.

Now let’s talk performance; I’ve done extensive testing to see how either method performs on average. I also did a control test with no part movement, so I’ll express the performance changes as a comparison to that. I’ll also express how each method would impact the user’s framerate, assuming the most they could achieve was 60 FPS without Roblox’s FPS cap.

Test 1: Changing a part’s CFrame every frame, 50 studs away from the player.
In this test, the operation lengthened each frame by an average of 30%. This means it would drop our example user’s framerate down to 44 FPS.

Test 2: Identical to Test 1, but now 500 studs away from the player. Frame time was increased 45% above normal, meaning the user framerate would drop to 41 FPS.

Test 3: A Part moving using simple Welds, 50 studs away from the player. Frame time was increased 53% above normal, meaning the user’s framerate would drop to 39 FPS. In this scenario, CFraming the part would definitely perform better.

Test 4: Identical to Test 3, now 500 studs away from the player. Frame time was increased by only 40%. This would put our user’s framerate at 42 FPS. This test shows that Roblox’s physics engine performs differently with more distance. In this specific case, it would be better to use Welds over CFrames.

Test 5: Identical to Test 3, however now we update the Weld’s C0 property every frame. You might want to do this type of operation if you had a custom animation system for welded parts. In this test frame time was increased by 56%, putting our poor user down to 38 FPS. This is probably the worst thing you could do, and would be much better off using a method similar to Test 1.

Test 6: Identical to Test 5 at 500 studs away from the player. Frame time was increased only by 41%. Dropping our user’s framerate to 42 FPS. This is marginally better than Test 2, however I don’t think it would look as smooth visually. Once again this is Roblox’s physics engine performing differently at great distances.

I hope that you can use this data I’ve collected to better decide on what method you want to use for moving parts around. This data was collected 1/30/2021, and it matches what I’ve experienced in past development, however Roblox could release an update any time that changes the behavior we found here.

7 Likes

Make those 10 parts massless so they weigh nothing, or just give them 0 weight.

You missed the point of the example. Yes there’s ways to disable some of the physical effects of welding parts, but that’s not the point of the post. I was using that example to point out how weld behavior can differ from just CFraming parts around.

And it was a flawed example. I just wanted to point that out.

1 Like