Search Unity

Persistent/Clear vs TempJob allocations

Discussion in 'Entity Component System' started by sebas77, Jan 20, 2020.

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,642
    It's a while I wonder if a Persistent/Clear is faster than a TempJob allocation. Didn't bother to check for lack of time, but I am interested in your thoughts
     
    Last edited: Jan 20, 2020
  2. fellowunitydeveloper

    fellowunitydeveloper

    Joined:
    Oct 23, 2019
    Posts:
    7
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    I always use persistent and clear (in job), as long as it makes sense.

    This doesn't really compare allocating vs clearing though.
     
    Last edited: Jan 21, 2020
    fellowunitydeveloper and sebas77 like this.
  4. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,642
    if the Arrays are big there is the chance that temp allocation may be faster than clear.
     
  5. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,642
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Depends on container, for example a clear on native list just sets length to 0. Doubt any allocation will be faster than that. In general most clears are pretty fast like this, and the ones that aren't like hashmap call clear on allocation anyway...
     
    sebas77 likes this.