Performance: Excess memory allocation in MyDataReceiver.UpdateBroadcastersInRange

Viktor Ferenczi shared this bug 5 months ago
Reported – Awaiting fix

Game version: 1.200.032


Method: MyDataReceiver.UpdateBroadcastersInRange


This method always allocates new HashSets, posing a constant GC pressure:


HashSet<long> longSet1 = new HashSet<long>();
HashSet<long> longSet2 = new HashSet<long>();

It should use pooled objects and just clear them instead of allocating new ones.


Best is to use a per-thread array of instances: ThreadLocal<HashSet<long>[]>


For a working solution please see MyDataReceiverPatch in https://github.com/viktor-ferenczi/performance-improvements


Alternative would be to use a bucket pool: MyConcurrentBucketPool<HashSet<long>>


Do not add these instances as members to MyDataReceiver, because it would involve a lot of unnecessary objects, increasing the overall memory consumption and lowering cache locality.


Run this test world in DS to reproduce (OneDrive due to its size): https://1drv.ms/u/s!AqEgz8G_d8TSh8wPzLoPp_dQDBRb7g?e=eBhsuv

Replies (1)

photo
1

Hello, Viktor,

thanks for letting us know. This issue was reported internally.

Kind Regards

Keen Software House: QA Department

Leave a Comment
 
Attach a file