View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0009873||New issues||Scripting||public||2018-06-10 16:18||2018-06-10 19:04|
|Summary||0009873: Fix unnormal CPU usage of unsynced setElementData()|
As we may all know, setElementData is using a lot of CPU and drains performance extremely when used pretty often each frame, even when not synced.
|Steps To Reproduce|
I could not measure it yet, but should getElementData be avoided aswell? It seems to run faster.
|Tags||No tags attached.|
crun t1 = getTickCount() for i=1, 1000 do setElementData(localPlayer, "test", math.random(9999), false) end t2 = getTickCount() outputChatBox(t2-t1)
Only took 38 miliseconds.
One frame at 50 fps needs 20 ms to execute, now imagine you have a busy server with only 500 things that need to be updated each frame. This would still take an additional 19ms to execute, lowering the fps from 50 to only 26 fps!
My server uses (for example) trails on water for torpedoes and ships and each trail consists of many single elements that need updates each frame. With element data this was unplayable, just 4 torpedoes lowered the fps from 50 to 30 on my i7, I can only imagine what happens to all the poor toasters that play MTA. After replacing element Data with lua tables this issue was fixed and even 300 trails on a screen are not noticeable. Unsynced setElementData should be exactly that fast.