Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Preformance Issues with the new input system.

Discussion in 'Input System' started by ODINKONG, Nov 11, 2020.

  1. ODINKONG

    ODINKONG

    Joined:
    Nov 4, 2014
    Posts:
    112
    I'm running into various lag spikes related to the new input system. I can't seems to pin them down to just one function, but they are all related to the new input system. They occur seemingly randomly with a mouse, keyboard and a controller.

    I've attached a couple profiler screenshots that might help.

    In the second screenshot 5 ms for preformed and canceled seems like a lot. preformed for this button plays a simple animation enables a low poly model a point light and a sprite. canceled only reports that the button was pressed in the log.

    Edit:
    CheckForUnpairedDeviceActivity seems to be another common culprit. 22 ms in the third attached screenshot

    I noticed that if I change the update mode for the input system to fixed update the lag gets literally 10 times worse over 100 ms for CheckForUnpairedDeviceActivity. I was using dynamic update with the 22 ms lag spikes.
     

    Attached Files:

    Last edited: Nov 11, 2020
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    We're looking into various performance issues ATM. CheckForUnpairedDeviceActivity in particular has a pending PR with significant performance improvements. There's still an overall susceptibility to event loads, though, that needs addressing. Even if per-event work is reasonable, the system overall can easily be brought to its knees just by spikes in event volume as there's no rate-limiting ATM.

    Note that large profiling spikes in DelegateHelpers almost always point to problems in callbacks rather than in the input system itself. For example, in the Profiler4.png shot, you can see that the spike is coming from the performed callback which is allocating GC memory in user code. Chances are high this is simply a garbage collection pass getting triggered (thus the more or less random hitching). Removing GC allocations will likely get rid of the hitching.
     
    ODINKONG likes this.
  3. ODINKONG

    ODINKONG

    Joined:
    Nov 4, 2014
    Posts:
    112
    Well first off thank you for the fast and detailed response.

    It sounds like I don't need to be worried about CheckForUnpairedDeviceActivity and you guys are on top of that so that's good to hear. We are at the begging of a new project so we don't mind waiting for that fix. Updates like this will be available in unity 2019 LTS through the package manager once they are ready correct? Overall the new input system has been amazing for us so we really appreciate your hard work!

    If you could clarify the last piece. You mean that I am creating some garbage in my preformed and canceled methods and I should look into my code for those events and optimize them so they create less garbage in memory?

    Also would you mind taking a look at this code. I have subscribed this function to preformed and canceled, and this is the function that was being called in that particular screenshot when I uncollapsed those preformed or canceled calls.


    Code (CSharp):
    1.  
    2.     public void WestButtonAction(InputAction.CallbackContext ctx)
    3.     {
    4.  
    5.             basicAttackInputDown = ctx.ReadValueAsButton();
    6.             if (ctx.ReadValueAsButton())
    7.             {
    8.             inputBuffer[inputBuffer.Count - 1] = inputType.Attack;
    9.             DoBasicAttack();
    10.                 Debug.Log("XbuttonPressed");
    11.             }
    12.             else
    13.             {
    14.                 Debug.Log("XbuttonReleased");
    15.             }
    16.  
    17.     }
    Am I right in assuming when it is released or canceled the only thing it's doing here is Debug.Log("XbuttonReleased");

    Also if that is the case why is that causing so much garbage allocation and extra ms.

    Thanks again fro the help!
     
  4. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Yeah, Debug.Log is one of the most expensive operations in Unity, hence that garbage amount.
     
    ODINKONG likes this.
  5. ODINKONG

    ODINKONG

    Joined:
    Nov 4, 2014
    Posts:
    112
    Ahhhh yeah right you are hahaha. I guess I underestimated how expensive that actually was, but if it logs on button press and it's expensive then this all makes a lot of sense. I'll give it another shot without the input logging. Thanks for the help guys I really appreciate it!
     
  6. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Correct.
     
  7. Jos_king1

    Jos_king1

    Joined:
    Apr 10, 2021
    Posts:
    1
    Hello I has similar problem. Please can you explain me why there such delay on readvalue<> .
    Code (CSharp):
    1.  void FixedUpdate()
    2.     {
    3.         _moveAxis = inputActions.PlayerLevelActions.Move.ReadValue<float>();
    4.         transform.position += new Vector3(_moveAxis * Time.deltaTime * speed, 0, 0);
    5.         Debug.Log($"Move axis {_moveAxis}");
    6. }
    It doesn't matter if ther is that debug or not. how it is possible, that longer I hold one of the keyborad for example A, debug log show longer that value 1 after i release keyboard (longer I hold keyboard, longer it shows bad value after i release). I mean there is some pending issue of value. It should immidiatly shows 0 value after I relaese, but it is still shows that value is 1 for while (depend how long was button holded....if I hold it short time delay of changing value is almost OK, If I hold button long this interval of bad value is longer after i relase button). Where is problem ? Why it is not instantly shows value 0 if it is in fixed update. It it caused because input is event ?

    I think It is some kind of "pending events called bug" I was try using all it should be used acroding tutorials, manuals, ect. (I tried all combiantions started, performed, canceled, [alone, together, only two]
    all variations has some pending issues with that reading value of keyboard pressed.
    Code (CSharp):
    1. private void OnEnable()
    2.     {
    3.         inputActions.PlayerLevelActions.Move.Enable();
    4.         inputActions.PlayerLevelActions.Move.performed += HandleMove;
    5.         inputActions.PlayerLevelActions.Move.started += HandleMove;
    6.         inputActions.PlayerLevelActions.Move.canceled += HandleMove;
    7.  
    8.     }
    9.     private void OnDisable()
    10.     {
    11.         inputActions.PlayerLevelActions.Move.Disable();
    12.         inputActions.PlayerLevelActions.Move.performed -= HandleMove;
    13.         inputActions.PlayerLevelActions.Move.started -= HandleMove;
    14.         inputActions.PlayerLevelActions.Move.canceled -= HandleMove;
    15.  
    16.     }
    All variations has some pending issues. If I put that first part of code upper in text into callback content like here: It acting different (worser for me) but anyway that bug about reading value in time is still here
    Code (CSharp):
    1.  private void HandleMove(InputAction.CallbackContext context)
    2.     {
    3.         _moveAxis = context.ReadValue<float>();
    4.        /* if (context.canceled==true)
    5.         {
    6.             _moveAxis = 0;
    7.         }*/
    8.         transform.position += new Vector3(_moveAxis * Time.deltaTime * speed, 0, 0);
    9.         // throw new NotImplementedException();
    10.      
    11.     }
     
    Last edited: Apr 10, 2021
    Unlimited_Energy likes this.
  8. ltomov

    ltomov

    Joined:
    Aug 3, 2017
    Posts:
    96
    In my case context.ReadValue() takes 11ms which causes a big drop in frame rate.
    This is happening on an Android device for the "Navigation" action (moving around with the arrows).

    Here's a screenshot from the Profiler:
    Screenshot 2022-01-06 at 17.30.28.png

    I'm using version 1.2.0 of the Input system.
     
  9. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    YES, please explain why when i am also using .ReadValue<float>() on the joystick its not returning 0 when thee position is 0, it sometimes return 0.75, 0.45. Its not reading from the current position and is holding onto some weird value. This makes it literally impossible to program controls for any type of game im doing. I am doing a podracer simulator that is making it impossible to set the blendtree animation correctly to the joystick position since its not really "reading" the current float value with that function. The input system has major issues that need to be fixed and it seems like its taking FOREVER. I will litterally release the joystick to the center position and Im getting retunr values every update call endlessly that will read 0.75, 0.45...thats WAAAy off. Now if it helps, this seems to happen the faster the values change, the less accurate it is and if you slowly ease into a joystick value, its more accurate, but this is NOT how this should work. Were not talking a little off, were talking about .ReadValue<float>() being 100% useless.
    podracer.PNG
     
  10. TheNullReference

    TheNullReference

    Joined:
    Nov 30, 2018
    Posts:
    258
    <ReadValue> takes 11ms???

    I'm pretty sure an entire frame of Half Life Alyx renders in 11ms.

    This is a serious issue. I think we need an input system that does a better job of getting us the raw input values from the devices, and bypassing string references and useful systems.
     
    Bovine likes this.
  11. Blepius

    Blepius

    Joined:
    Mar 9, 2021
    Posts:
    68
    Hiya!

    I've noticed your post is two years old here. Do you know if New Input is a recommended solution for mobile development these days?
     
    Ogaudreau likes this.
  12. Bovine

    Bovine

    Joined:
    Oct 13, 2010
    Posts:
    177
    Any news on this? I had a build working fine on Quest 2 but when I use the right stick on the steam deck the frametime collapses leading to huge spikes for no apparent reason!?!?
     
  13. TheNullReference

    TheNullReference

    Joined:
    Nov 30, 2018
    Posts:
    258
    It still seems like the recommended approach when using VR is to use OVR.Input instead of the input system.
     
  14. Bovine

    Bovine

    Joined:
    Oct 13, 2010
    Posts:
    177
    This was actually me - I had a debug line loitering on the right stick event ‍♂️

    It was fine (probably) for VR but was presenting radically FPS failure on steam deck, leading me to believe it was not impacting VR.
     
    TheNullReference likes this.