Search Unity

Unity 5 - Profiler shows physics spikes on Android device.

Discussion in 'Physics' started by kimcgm, Apr 8, 2015.

  1. kimcgm

    kimcgm

    Joined:
    Jul 30, 2013
    Posts:
    11
    Hi there,

    I'm developing a game on mobile device.
    I notice my game started to slow/pause every so often and decided to look it up in the profiler.

    I've the profiler hooked onto Android Sony Z2 (Quad Core Arm CPU).

    With no object moving in the scene (except for some particles), I noticed the physics spikes a fair bit on the device but not on my PC (mac). Screen Shot 2015-04-09 at 1.12.57 am.png

    In the project, I have only 1 rigidbody and have already remove majority of the collision model. In the physics settings, I have unchecked all the collision pair under Layer Collision Matrix.

    I noticed at the bottom of the worker thread, there are some expensive functions (AABB test, rigidBodyNarrowPhase). Could the few remaining collision models and 1 rigidbody caused all that (even when there are 0 active rigidBodies and 0 contacts reported in the Physics graph)?


    kimc
     
    IgorAherne likes this.
  2. jtbentley

    jtbentley

    Joined:
    Jun 30, 2009
    Posts:
    1,395
    Unless you're setting the position of the object every frame (or fixed update), I don't see any reason why you'd see a spike at all. Are you performing any other actions with the rigidbody components at all?
     
  3. kimcgm

    kimcgm

    Joined:
    Jul 30, 2013
    Posts:
    11
    For that run I turned off alot of collider and removed all but 1 rigidity. At one point i was setting the same position every frame. I have turned that off since than but still didn't help.

    I'm hoping it is something silly I'm doing (At least I will be something I can fix by myself).

    Once I get home, I'll try to run a comparison of the same code on the mac (in editor) vs android device.
     
  4. jtbentley

    jtbentley

    Joined:
    Jun 30, 2009
    Posts:
    1,395
    Drop me an email of your code that pertains to the rigidbody, I'll check it out. I haven't moved to U5 yet (I'm project locked to 4.6.3 by about 5 projects), but meh, it won't be too different :)
     
  5. VictorFR

    VictorFR

    Joined:
    May 4, 2014
    Posts:
    15
    hi. i have some problem and i try turn off all object but physics.processing still here. Why did you do for it?
     
  6. kimcgm

    kimcgm

    Joined:
    Jul 30, 2013
    Posts:
    11
    Jamie,

    See attached image. Same code base, one ran in Editor, the other ran on Android.
    In this setup, I have not strip out anything. 1 complex mesh collider. 21 rigidbodies + collider and 8 trigger collider.
    The only thing that moves are the ones with 21 rigidbodies. The rest are stationary colliders.
    001.jpg

    I believe the physics spike has always been there throughout the ran. But it just stands out when there are no active rigidbody and zero contacts.

    Anyway, I'm not sure if I'll spend more time looking into the Android performance. Need to get myself an iOS device to see what happens there. But first... i need to get an iOS dev license. There goes $99AUD. :-(
     
    Stormy102 likes this.
  7. ScoCorp

    ScoCorp

    Joined:
    Aug 6, 2014
    Posts:
    1
    We are having the same issue. Android (LG Nexus 4), Unity 5.1.0b6.

    Even with a single rigid body (CircleCollider2D) we are seeing spikes of 40-60ms in Physics.Processing.

    From the Profiler timeline, it looks like the physics tasks are being run in *series* on the worker threads. And they're taking much longer than expected. The profiler hierarchy doesn't reflect the timing values (perhaps because they are run on worker threads), but you can see it in the timeline.

    physics-processing-spikes.PNG physics-processing-spikes-timeline.png physics-processing-otherframe.PNG

    Has anyone made any progress on this?
     
  8. Benjamin.chevalier

    Benjamin.chevalier

    Joined:
    Jul 3, 2014
    Posts:
    21
    I confirm the issue on Android, it kills our framerate. On some older devices our game should run close to 60fps, but currently runs at 15fps because of physics. Note we have 0 Unity physics in our game, our engineer re-wrote its own. This didn't happen on pre Unity 5 versions.
     
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,972
    'Physics.Processing' is 3D physics; nothing you do on 2D physics will affect it. 2D physics processing will be shown as 'Physics2D.FixedUpdate'.
     
  10. viame

    viame

    Joined:
    Jan 17, 2013
    Posts:
    7
    I have same problem too on android device
     
  11. OMGWare

    OMGWare

    Joined:
    Mar 4, 2014
    Posts:
    24
    Same exact issue here, tested on Nexus 4, Oneplus One and Nexus 7 2nd gen, there are a lot of really high spikes (20-80ms) figuring under Physics.Processing method.
    Test case:

    - 1 dynamic rigidbody with 1 sphere collider (non-trigger)
    - 1 plane with static collider (non moving and non trigger)
    - physics matrix with only 1 checkbox for collision between two custom layers (Plane and Ball)
    - FixedUpdate method completely empty on both objects as no scripts were attached to the objects.

    Even disabling the colliders and all the checkboxes in the physics matrix and no gravity on the ball's rigidbody, Physics.Processing is still taking up 5ms average (with peaks near 8-10ms). Seriously?

    I tried this test case on an empty scene in my project, no way a single ball bouncing on a plane gets me physics spikes even as high as 20ms on a single frame on a OnePlus One....I believe there's a bug here.

    This issue seems to be overlooked, as it stands now it completely kills performance on Android.
     
    Last edited: Jul 17, 2015
  12. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    sorry for this taking so long. The bug has been assigned to the Android team now.
     
  13. Benjamin.chevalier

    Benjamin.chevalier

    Joined:
    Jul 3, 2014
    Posts:
    21
    Super great to hear, thanks !!
     
  14. flumbatron

    flumbatron

    Joined:
    May 6, 2015
    Posts:
    5
    Any update on this? My android framerates are pretty boned by Physics.Processing spikes with no 3d physics in the game. Running 5.1.2 / OnePlus One.
     
  15. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,082
    Morten, Same exact issue here but Windows 7 64 radeon 7970 last drivers. In a empty project
    No Camera or light in a fresh new Unity 5.2.b05f installation
    "physics.processing" take 98.9% of resources in that peak and fps drop to 20
    I do not think is a Android problem since i'm in windows.
     

    Attached Files:

    Stormy102 likes this.
  16. Benjamin.chevalier

    Benjamin.chevalier

    Joined:
    Jul 3, 2014
    Posts:
    21
    Hello there, How is it going with this ?
    Thanks !
    ben
     
  17. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Hi,

    The android team have been working on it and the problem seems related to interactions between our job system, how PhysX creates jobs and how Samsungs big.LITTLE cpu balancing tech works.

    The solution we're are close to is ..... bailing out when there is no physics in the scene ;)
     
  18. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    AlanMattano, Looking at that pic I think some info is missing from the profilers, because there is no PhysX tasks actually taking up the time. I'll add it in.
     
  19. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    AlanMattano, or maybe not. It just processes jobs. Can you show a screenshot of the timeline profiler? There might be some other work in the job system.
     
  20. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,082
    Timeline in empty scene screen shot. Default settings Unity 5.2.b05f DX11.
    If i move an object via script or via physics, same result, loosing visual fluidity in all that peaks (19 fps). Changing time steps do not affect the issue. Thanks for the interest.
     

    Attached Files:

  21. Benjamin.chevalier

    Benjamin.chevalier

    Joined:
    Jul 3, 2014
    Posts:
    21
    Hi @MortenSkaaning, this is great news ! What Unity release would have the fix in ?
    Thanks !
     
  22. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    I think initially it would go into 5.2 if there is time for it, or a 5.2 patch if it misses the RC cutoff. If there is demand for it we will backport it to 5.1.
     
  23. MarimoAli

    MarimoAli

    Joined:
    Jan 16, 2015
    Posts:
    18
    Hello,

    what is the current schedule if there is any for 5.2 ? As this is our only major "bug" in our game, since we don't use physics and max number of contacts in our scenes are 1-3, so were essentially sure this would fix some of the performance issues.

    Thanks for keeping us up to date!
     
  24. Benjamin.chevalier

    Benjamin.chevalier

    Joined:
    Jul 3, 2014
    Posts:
    21
    Hi @MortenSkaaning, thanks for the update.
     
  25. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    @MarimoAli we do weekly patch release so if the fix does not make it in time for 5.2.0 then it will go into the weekly patch.
     
  26. MarimoAli

    MarimoAli

    Joined:
    Jan 16, 2015
    Posts:
    18
    Hey, @MortenSkaaning alright, thanks for the heads up, we will be waiting patiently and hope it arrived next patch :).
     
  27. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,082
    Spickes 24fps Unity 5.2.0f2
    V Sync ON and V Sync OFF. Quality Settings Fastest. Default Scene
    Timeline screenshot:
     

    Attached Files:

    Last edited: Aug 23, 2015
    Stormy102 likes this.
  28. MarimoAli

    MarimoAli

    Joined:
    Jan 16, 2015
    Posts:
    18
    @MortenSkaaning just wanted to mention, that the latest patch Patch 5.1.3p1 has fixed our issues on Android.
     
    MortenSkaaning likes this.
  29. mrbenn

    mrbenn

    Joined:
    May 1, 2015
    Posts:
    13
    Saw there was the fix in 5.1.3p1 so upgraded to that version but I'm still getting the issue on the OnePlus One with Android 5.1.1 - big Physics.Processing spikes.
     

    Attached Files:

  30. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
  31. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,082
    Passing from Windows 7 to Windows10 and last Unity 5.2.1f1 release
    Spickes 28ms 37FPS is a big improvement and there is much less visible stops in the motion of the objects at that spicks.
    Thanks for the improvement to the Android team and Morten.

    PS: I was thinking: Logarithmic Graphic option in the inspector can help to show better the spicks. Graphics in the inspector are liner? Or adding a line for example at 30FPS (Expose an input float FPS value to add a color line or more than one).
     

    Attached Files:

  32. jiejieup

    jiejieup

    Joined:
    Mar 22, 2013
    Posts:
    2
    I have tested my android device, and found big performance spikes on Physics.Processing using Unity 5.2.0f3. Although my game didn't use any physics components, only some collier boxes used by NGUI.
     

    Attached Files:

  33. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    @jiejieup, so far, when you add a Collider we still update PhysX.

    When we complete the upgrade to PhysX 3.3.3 there should be even fever spikes because some of the internal PhysX thread communication was optimized.
     
  34. Kubold

    Kubold

    Joined:
    May 10, 2012
    Posts:
    339
    Right, so...

    Unity 5.2.1p2, Win7. Physics.Processing spikes every 4-5 seconds, even in empty level with just a plane and a cube. So, in effect, every 5 seconds game goes to 0 fps for a moment.

    Case 733968.

    Clipboard01.jpg
     
    Stormy102 likes this.
  35. GameArt

    GameArt

    Joined:
    Feb 24, 2013
    Posts:
    78
    We are having the same issue on Windows 7 machines running 5.2.0.

    I see the spikes for Android were addressed in 5.3. I mention this issue here, because besides the platform everything else appears the same.
     
    Stormy102 likes this.
  36. Kubold

    Kubold

    Joined:
    May 10, 2012
    Posts:
    339
    Yup, looks like problem is gone in Unity 5.3.0 beta 1. No Physics.Processing spikes, good job Unity.

    EDIT: I take that back. Physics.Processing still causes stutter in Unity 5.3.0 beta 1. It's especially visible in VR (instantly sick when the game does 0fps every 5 seconds). This time it's when you have a rigid body on the scene (just one is enough).
     
    Last edited: Oct 15, 2015
  37. sanmn19

    sanmn19

    Joined:
    Jun 30, 2013
    Posts:
    56
    Issue still present in 5.2.1f1 which is the only stable release available to devs right now
     
    Stormy102 likes this.
  38. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    5.2.2f1 still has issues too. I don't know if my issue is the same though. My spikes aren't as persistent as OP but more similar to @Kubold where it will spike every several seconds. And it's not android specific because they happen even when running on desktop/editor.

    There are no physics objects in the scene. Only UI elements. And when this spike happens, absolutely nothing is moving or doing anything at all. Just a random physics spike for no reason. I've seen it as high as 30-40ms (in editor). Random unstoppable lag is not good for business.

    EDIT: Also still happening in 5.3.0 beta 3
     

    Attached Files:

    Last edited: Oct 22, 2015
    Stormy102 likes this.
  39. Kubold

    Kubold

    Joined:
    May 10, 2012
    Posts:
    339
    I am courious if we are like the only people who have this. I can't google any other threads about this, which is weird, because those Physcis spikes are a showstopper. Game literally freezes for a moment, every few seconds, because of those spikes. I have a small VR demo game ready to ship, but I can't release it because of this.

    I would like to know if this is a global Unity problem, but nobody cares, or is it hardware specific (for example it only occurs on a veeeery specific hardware config). Btw. I checked Web Player and there is no problem. It just happens in Windows in my case (I didn't check mobile).
     
    Stormy102 likes this.
  40. BalazsBalazs

    BalazsBalazs

    Joined:
    Oct 7, 2013
    Posts:
    8
    I have the same problem...
    Win7 standalone build, Unity 5.2.2f1
    Only one rigidbody (ball) and total random time Physics.Processing laggs..
    It is very annoying ..
    I have 200+ FPS and after freeze the game for ~0.5 second randomly and continue the 200+ FPS
    Do something with this pls...
     
    Stormy102 likes this.
  41. polope

    polope

    Joined:
    Apr 1, 2015
    Posts:
    3
    I have the same problem
     
  42. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    I'm hacking together a profiler for the job system so we can see what's going on in your machines. It might not work since collecting any data will change how the threads are executing and make the problem "disappear", but it's worth a shot. It might take a few days. I expect I can make a build off the 5.2.2f1 release.

    In the mean time it would be very useful for me to learn about your hardware + software configs. If you have the problem can I get you to post:
    - Your processor type, including how many cores it has.
    - You graphics card type, including if you are using multiple at once.
    - If you're forcing v-sync.
    - What Windows version you're running.
    - What applications you are running in the background, to test if external cpu load has an effect.
    - If you can repro on a super simple scene, if so please describe how to recreate it.
     
    Stormy102 likes this.
  43. BalazsBalazs

    BalazsBalazs

    Joined:
    Oct 7, 2013
    Posts:
    8
    Thanks MortenShaaning.
    My environment is this:

    Windows7 64bit
    Msi b85-g43 (motherboard)
    Intel core i5 3.40Ghz x4 (cpu)
    Geeforce GTX 760 , 2Gb (videocard)
    8Gb ram
    Everything with default settings.

    At the test only the Unity 5.2.2f1 run.
    Standalone windows x86 build target.
    Test scene is a new scene: default main camera, default light, default 3d Plane added (meshcollider).
    Default good quality settings (good)
    so v-sync off
    Random time physics.processing ~98% but inside the physics.processing every row is 0 and at this point the game freeze out for ~0.2 or less second, but I can see this and annoying.
    I also sent a bug report from the editor. Is this problem just for few users?
     
  44. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,082
    I have this same problem since Unity4, Windows7 32 and 64, GPU gtx460, CPU i3 2 core,RAM 4Gb.

    Actual configuration specific for debugging spikes :

    Hardware
    - CPU Processor Intel Core i7-2600K, 3.80Ghz, 4 cores.
    - RAM Memory 16Gb 1333Mhz (2x7GB)
    - GPU Graphics card (x2) Xfx R7970, using 2 graphics cards without-crossfire.
    - Monitors (x2) 1920 x 1200 attach to each video card.

    Software
    - Unity5.2,2f1
    - v-sync. OFF
    - Windows10 Home 64bit (last update). Upgrade from genuine Windows7
    - Applications you running in the background: Only Unity, No Defender or else antivirus running. No One drive, Adobe or Chrome. No internet at the test run. I turn off all software for debugging.
    - In an empty scene, all default.
    Go to QualitySettings, level: Fastest
    Add this script.Then press play in editor


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DebugPhysicsFPS : MonoBehaviour
    5. {
    6.     private float FpsSpikes = 0f;
    7.  
    8.     void Update ()
    9.     {
    10.         if (Time.deltaTime >= 0.02f) {
    11.             FpsSpikes = 1f / Time.deltaTime;
    12.         }
    13.     }
    14.  
    15.     void OnGUI ()
    16.     {
    17.         GUILayout.Label ("FPS spikes:" + FpsSpikes);
    18.     }
    19. }
    Resoults
    - In Editor: 36fps spikes each second.
    - In build Game: 55fps spikes.


    Visual Test
    - In an empty scene, all default.
    - Go to QualitySettings, level: Fastest
    - Add a Cube at position Y73 Z128
    - Attach Rigidbody
    - Then press play in editor

    Look the motion of the object freefall. The movement is not a constant acceleration. Has small visible stops (in fps spikes). If you increase Fixed Timestep to 0.005 the stops are more visible in contrast to the smooth motion.
     
    Last edited: Nov 12, 2015
  45. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Hmm, I wonder if vsync could be a factor. Could you try turning it off?
    Anyways, the VR team and the Core team are now working on this problem. I've taken their preliminary results and I'm currently waiting for a 5.2.2 build with those changes to be generated.

    There are no guarantees how well it will work since fixes are developed on 5.4, and will later be backported.
     
  46. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,082
    All this screenshots are made with
    - Unity vsync off

    - QualitySettings, level: Fastest
    - Hardware settings are in HQuality

    note: look the Hierarchy game objects

    Since last improvement,
    spikes are shown in Rendering and no spikes in Physics.
    I do not think is a Ati problem since the other user BalazsBalazs is using Nvidia.

    No light.jpg EmptyScene.jpg No camera.jpg

     
    Last edited: Nov 12, 2015
  47. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,082
    All this screenshots are made with
    - Unity vsync on (Look in the screenshot inspector for more detail)
    - QualitySettings, level: Fastest
    - Hardware settings are in HQuality

    In Every Sec V Blanc FPS frame rate can jump from 61 to 25FPS spike in short period.
    (I do not understand why is shown more than 30). But this jump or drops in a not constant fps rate makes loosing of motion smoothness. Osculation of the fps is less less preferable at low frame rate.

    In EverySecVblanc25FPSspike- CPU Usage.jpg Every Second V Blanc 25FPSspike.jpg Every Second V Blanc 61FPSspike.jpg Every V Blanc.jpg In EverySecondVblanc25FPSspike - Memory.jpg
     
  48. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Hi,

    The bleeding edge untested 5.2.2f1 build with the experimental jobqueue changes is here: http://beta.unity3d.com/download/85a7a8acd02f/public_download.html

    Remember do to a backup of your project as I can't guarantee nothing will be corrupted.

    These changes are finding this way into the mainline at the moment.

    Please let me know how this build affects your situation.
    Regards,
    Morten
     
  49. Kubold

    Kubold

    Joined:
    May 10, 2012
    Posts:
    339
    Clipboard01.jpg

    Repro:
    - Make new project in Unity 5.2.2f1
    - Add a Plane and mark it static
    - Add a cube and add a rigid body to the cube
    - Press Play and observe how profiler shows Physics.Processing spikes once in a while (randomly, once every 5-15 seconds)

    Notes: it happens on every Quality level, v-sync on or off, doesn't matter.

    Hardware:
    Desktop PC
    i5-4690 3.5GHz
    12 GB RAM
    Win 7 64 bit
    GF 970

    I might mention that I have Oculus v.0.7 runtime installed.
     
    Stormy102 likes this.
  50. Kubold

    Kubold

    Joined:
    May 10, 2012
    Posts:
    339