This object is in archive! 
Excessive memory allocation in MyLargeTurretTargetingSystem
Solved
Game version: 1.200.032
Both server and client, but worse on multiplayer servers.
Problem: Memory allocations in frequently called methods of MyLargeTurretTargetingSystem.
How to reproduce:
- Download and extract the test world (OneDrive, due to its size):
https://1drv.ms/u/s!AqEgz8G_d8TSh8wPzLoPp_dQDBRb7g?e=eBhsuv - Load the test world into DS or client.
- Use dotTrace to capture a timeline snapshot for 10 seconds.
- Select .NET Memory Allocations in the Events filter.
- The turret targeting system methods listed below should be at or near the top of the hotspot list.
Affected methods
- SortTargetRoots
- UpdateVisibilityCache and the whole visibility cache logic
Please see the memory profiler screenshot attached, see the top 2 items listed.
Remarks
- Do not use ArrayExtensions.EnsureCapacity if you don't need to keep the existing array items. Whenever it needs to "grow" the array, it creates a new one and copies all items over! We don't need it if the goal is only to reuse the array.
- Reuse collections as much as possible. Some of them reused, some others are missed and a new one is always allocated. It imposes GC pressure, causes slowness and lag.
- Do not use ConcurrentDictionary, it has horrible performance. You are way better off by just using a simple Dictionary<K, V> generic type and lock the whole collection on access.
Please see the related patches in the Performance Improvements plugin on how to fix the above.
Search for: MyLargeTurretTargetingSystemPatch
Files:
ExcessiveMemory...
Hello, Viktor!
Sorry, you're experiencing these issues. I will admit I don't have a huge amount of knowledge of dotTrace but have followed your instructions. When viewing the hotspots afterwards, I'm not able to see a mention of the targeting system that you have in yours. Should I be doing something in-game to activate this? I apologise for what is probably a silly question. I'd like to get this reproduced but so far after multiple attempts, this is not showing for me. Any tips in the right direction would be excellent.
Kind Regards
Laura, QA Department
Hello, Viktor!
Sorry, you're experiencing these issues. I will admit I don't have a huge amount of knowledge of dotTrace but have followed your instructions. When viewing the hotspots afterwards, I'm not able to see a mention of the targeting system that you have in yours. Should I be doing something in-game to activate this? I apologise for what is probably a silly question. I'd like to get this reproduced but so far after multiple attempts, this is not showing for me. Any tips in the right direction would be excellent.
Kind Regards
Laura, QA Department
You changed the logic in game version 1.202.048 (Automaton Beta), but it is still using ToArray() and EnsureCapacity, making it slow due to excess memory allocation.
Please re-read the ticket and the comments above above, then optimize to allocate as little memory as possible the least often as possible. Object reuse can do wonders to reduce/eliminate lag. Otherwise combat on multiplayer servers will be sluggish.
I give up patching your changing code, please fix it properly on your side.
You changed the logic in game version 1.202.048 (Automaton Beta), but it is still using ToArray() and EnsureCapacity, making it slow due to excess memory allocation.
Please re-read the ticket and the comments above above, then optimize to allocate as little memory as possible the least often as possible. Object reuse can do wonders to reduce/eliminate lag. Otherwise combat on multiplayer servers will be sluggish.
I give up patching your changing code, please fix it properly on your side.
Hello, Viktor,
thanks for updating this thread.
Issue was reported into our internal system.
Kind Regards
Keen Software House: QA Department
Hello, Viktor,
thanks for updating this thread.
Issue was reported into our internal system.
Kind Regards
Keen Software House: QA Department
Hello, Engineers!
We're happy to inform you that the upcoming "203" update contains a fix for the bug you have reported. Thank you for taking your time to inform us about this issue and making Space Engineers better.
If you are still experiencing the bug on the new version, please let us know by commenting here or opening a new thread.
We are closing this thread as "Solved".
Kind Regards,
Keen Software House: QA Department
Hello, Engineers!
We're happy to inform you that the upcoming "203" update contains a fix for the bug you have reported. Thank you for taking your time to inform us about this issue and making Space Engineers better.
If you are still experiencing the bug on the new version, please let us know by commenting here or opening a new thread.
We are closing this thread as "Solved".
Kind Regards,
Keen Software House: QA Department
Replies have been locked on this page!