Setting Joint.C1 property within a recently modified assembly reduces performance and can cause a freeze

Reproduction Steps

These are the steps used in the place file I provide below:

  1. Start play solo, then do the next two steps using scripts:

  2. Create new assemblies (10k total parts, each assembly has 20 parts each) using Welds or Motor6Ds. The assemblies should be flat (no hierarchies of joints, all parts should just be connected directly to the root part).

    • For my particular use case all the parts have CanQuery, CanTouch, CanCollide, and CastShadow disabled, and CollisionGroup set to a group that cannot collide with anything else.
  3. Immediately set the joints’ C1 property (other properties probably work too, but I haven’t tested them). This will cause the performance issue. To cause the freezing issue, the value you set the C1 property to should be really big, like CFrame.new(10e8, 10e8, 10e8).

  4. (If you haven’t frozen) open the microprofiler, and move your camera around, and observe choppy frame times. Dump some frames and check the RaycastBroadphase label.

To prevent the issues from happening, directly before step 3 do the following (this is step 2.5):

  • Call workspace:Raycast() or RunService.Stepped:Wait()

Here is the reproduction file with a more in-depth explanation of these things:
assembly_performance_bug.rbxl (40.5 KB)


Expected Behavior

There should be no long-term impact in performance and no freezing when you set Joint.C1 in an assembly that is waiting to be processed. It’s fine if there is a temporary performance difference, like a bunch of extra work being done to process things correctly when you set Joint.C1, but long-term behaviour should be consistent and correct no matter what order assembly processing and property setting are performed in.

Actual Behavior

Performance reduction: An observed large amount of time taken by the RaycastBroadphase label in the microprofiler. Presumably, parts in the assembly are becoming visible to RaycastBroadphase when they were not visible to it previously. Problematic when I have a large numbers of parts in assemblies.

Freezing: With large values of Joint.C1 the game will become completely unresponsive (for long enough for me to give up waiting and kill the process).

I believe this is related to when the ā€˜assemble’ microprofiler label runs - if Joint.C1 is set before it runs, we have the problems, if Joint.C1 is set after it runs, we are fine. So I view it as being a problem of modifying joints when the assembly is in an ā€œinvalidatedā€ state.

Workaround

Wait until the assembly has been updated (i.e. ā€˜assemble’ microprofiler label runs). I think you can rely on it being done before RunService.Stepped, so you can do RunService.Stepped:Wait(). I believe you can also force it to run immediately by calling workspace:Raycast(), which works too (though I may be wrong about why).

Issue Area: Engine
Issue Type: Performance
Impact: Moderate
Frequency: Constantly

7 Likes

i can vouch for this, i have a few functions in my game that change joint placements on a clients character after they loaded in, appaerently it causes them to straight-up crash

I’d like to chime in here, I don’t think it’s related to joints. I don’t change any joints and as of today Raycast broadphases just started taking WAY too long. This definitely wasn’t an issue yesterday.

Here’s some just casting to terrain, taking 2ms each.

1 Like

Interesting, though that looks like it could be an unrelated issue - you can compare our microprofiler screenshots and see that they are spending lots of time doing different things.

Yours is spending a lot of time on terrain, mine is spending a lot of time doing whatever RaycastBroadphase does normally (which is probably trawling through the 10k parts from the assemblies).

Thanks for the report! We’ll follow up when we have an update for you.

1 Like

Could you check whether you’re still seeing this issue?

I cannot repro and the physics broad phase has since seen significant changes to support shapecasting, so this may no longer be an issue.

The freezing issue is no longer happening, but the raycasting performance issue is still occurring. (Just to confirm, you need to toggle the commented state of line 158 of the Client script to enable/disable the raycasting performance issue.)

Line 158 uncommented:


Line 158 commented: