View Issue Details

IDProjectCategoryView StatusLast Update
0009873New issuesScriptingpublic2018-06-10 19:04
Reportereinheit-101Assigned To 
Status newResolutionopen 
Summary0009873: 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.
I see no reason why such a simple functionality should be that costly, and that's why I ask the MTA team if someone could fix that at least for unsynced purposes or maybe come up with an explanation why it may be (?) impossible to fix.

Steps To Reproduce

I could not measure it yet, but should getElementData be avoided aswell? It seems to run faster.

TagsNo tags attached.



2018-06-10 18:20

manager   ~~0026555

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.


2018-06-10 19:04

reporter   ~~0026556

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!
I thought this would never be a Problem until a year ago I realized that we could save massive performance by replacing element Data with a Lua table.

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.

Issue History

Date Modified Username Field Change