Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question NativeHashMap vs NativeArray

Discussion in 'Entity Component System' started by somebodySB, Jul 28, 2023.

  1. somebodySB

    somebodySB

    Joined:
    Nov 30, 2018
    Posts:
    13
    I am planning to replace NativeHashMap with NativeArray in my project (by converting the original IDs filled by the designers into sequential IDs), because theoretically, NativeArray should always have better performance than NativeHashMap.

    However, today I tested the read and write performance of both data structures. Without enabling BurstCompile, the results were consistent with the theory, where NativeArray was always faster. But after enabling BurstCompile,the writing time of NativeArray is half that of NativeHashMap, while the read time was almost the same.
    In the case of testing a small number of reads, NativeHashMap is always faster than NativeArray.

    the size of data above is 10000+,and I tested a less size(500+)just now,the performance of NativeArray is worse.writing time is also more than NativeHashMap this time.

    The result confused me.I would like to know why BurstCompile causes this result, as it clearly contradicts the inherent characteristics of the data structures.

    Unity version: 2021.3.0f1 Entities version: 0.17.0
     
    Last edited: Jul 28, 2023
  2. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    86
    You're likely not going to get much support for Entities v0.17 given that it's no longer supported. I'm probably wrong, but I vaguely recall there being issues with NativeArray's and v0.17 which I believe were corrected in v0.50+.

    Any particular reason you're sticking to v0.17? v0.51 was much improved. And if the goal was to aim for a production release then you should ideally use v1.0+. However, I have had more issues with v1.0 than I have v0.51 for my use case.
     
  3. somebodySB

    somebodySB

    Joined:
    Nov 30, 2018
    Posts:
    13
    thank you for reply.However,it's a bussiness project so I don't have the right to upgrade project.The lead developer mentioned that he had tried to upgrade the project but there is a large of code to change,and it would impede the progress so he gived up on it.