Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Profiler PHysics.SyncRigibodyTransform/SyncColliderTransform performance issues

Discussion in 'Physics' started by snacktime, Dec 29, 2017.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    1,605
    So up to a point the numbers reported in the profiler look ok. 500 rigidbodies being moved/rotated with MovePosition/MoveRotation and 850 or so sync's showing in the profiler.

    But every now and then, just for a single profiler frame, that numbers jumps to 15x - 20x that amount.

    But the main problem is that it hits a tipping point where something is getting backed up internally, and you go from 70fps to 2, and every profiler frame has the insane sync counts. 100 to 500 objects scaled up fine, somewhere between 500 and 600 it just takes a nosedive. Like something is unable to keep up.

    Fortunately for me I don't need that many, it was just a new implementation I was stress testing.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,147
    How often does that happen? I've encountered a similar problem in a different scenario. A frame drop happens exactly each second. That situation started around Unity 5.6 - 2017.

    In my case, it prevents me to record smooth videos because a noticeable frame drop occurs each second, even in the final builds.
     
  3. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    1,605
    I can reliably repro it.
     
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    1,605
    So got this really bad today and found that the trigger was from calls to Physics.OverlapSphereNonAlloc. So once it was running and showing like 11k transforms being synced, I set the layermask to nothing, everything went back to normal. I then added back the layers to the mask while playing, still normal.

    I am running the overlap calls within an InvokeRepeating which might be significant, although it shouldn't cause this type of behavior. It's making like 50 calls every 2 seconds.

    Really strange behavior it acts like it gets backed up somehow, but the numbers involved are wrong, it's like it gets magnified many times over once it hits the tipping point.
     
  5. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    1,605
    Ya when I remove the layers from the mask while playing, the insane transform sync counts gradually recover over a few seconds. Tried moving the overlap calls into FixedUpdate but didn't help so InvokeRepeating doesn't seem to matter.
     
  6. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    1,605
    I narrowed this down to it's just a matter of MovePosition/MoveRotation causing transform syncing to go nuts at a certain threshold.

    To test just create a bunch of objects with kinematic rigidbodies, and say MoveRotation every fixed update and just change Y by 0.00001. Threshold is probably computer specific, for me it's between 800 - 1000.
     
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    22,524
    Does Unity know?
     
  8. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    1,605
    They will now, was waiting until I had the time to narrow it down before submitting a bug report.
     
    hippocoder likes this.
  9. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    1,605
    Having issues with filing bug reports, say's they are submitted but no auto replies so can't post the case number.

    In any did some tests with transform autosync disabled and calling Physics.SyncTransforms(). I sort of expected the behavior I saw, kind of confirms it's almost got to be something wrong in the auto sync logic.

    Behavior is that it scales up smoothly, profiler doesn't show a huge spike in sync calls at the tipping point.

    It is really expensive though. Like realistically even with auto sync disabled you can forget having more then a few hundred moving kinematic rigidbodies in a real game scene.

    So the funny thing here is that the auto sync stuff is there largely because of the new transform update stuff coming in 2018. Can't remember the post off the top of my head but saw that comment the other day by someone from Unity. So basically it appears that they broke being able to have a reasonable number of rigidbodies, to support having an insane number almost nobody will ever need:) I'm not going to go back to 5.6 to test that hypothesis, but you would think if kinematic rigidbody performance has been this bad for a long time, you would have heard about it before now.
     
  10. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    1,605
    FYI case number for this is 985751. Had some issues with bug reports not going through over the weekend so it's a bit late.

    Anyways wanted to report on the status of this in 2018 beta. The bug is still there, but it looks like transform syncing generally is faster and using less cpu. Which is probably why it only triggered once I had 5000 objects in my test case. However at 5000 profiler was showing 80,000 transforms syncing. Test case is a simple MoveRotation by 0.0001 every FixedUpdate.
     
  11. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,305
    The issue is there in 2017.3 too. Over 3ms spent in SyncColliderTransform with only 200-300 rigidbodies.
     
  12. Captain_Pineapple

    Captain_Pineapple

    Joined:
    Nov 9, 2016
    Posts:
    1
    I have a similar Problem regarding Physics.syncColliderTransform(). Only 2 Rigidbodys, but on has around 1600 Child Transforms with aroudn 1500 colliders. Physics.SyncColliderTransform takes up minimum 33% of total CPU usage...
    I am currently using Unity version 2018.1.
     
  13. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    1,605
    That's kind of expected though. That's an insane number of child colliders, basically don't do that. Whatever you are trying to do, there is a better way.