Search Unity

super slow null check

Discussion in 'Scripting' started by januszbadziej1965, Nov 10, 2018.

  1. januszbadziej1965

    januszbadziej1965

    Joined:
    Mar 5, 2018
    Posts:
    13
    hey, i am very disappointed with unity perfomance, but maybe it is my fault so i wanted to ask about my code.

    i am traversing a single linked list, and on every node i am checking for null.
    On low end pc it can take even 10ms with very large lists.

    here is my code:
    Code (CSharp):
    1.  
    2.         while(n)
    3.         {
    4.           // do something
    5.            n =n.next;
    6.         }
    i know that unity has custom == operator or something, but does it mean that I can't do anything to speed it up? Maybe I should use List< > instead? But I am remvoing and adding often...
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    1,867
    What's the "do something" part? That's most likely the cause of any performance issues. For confirmation, comment that part out and profile again.

    Also, how big is your LinkedList<>?
     
    Antypodish likes this.