Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

super slow null check

Discussion in 'Scripting' started by januszbadziej1965, Nov 10, 2018 at 10:43 PM.

  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,746
    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.