Furzy Posted September 12, 2019 Share Posted September 12, 2019 (edited) Hey all, some tips to get best performance in server? use more tables than elementdata? (im not sure, i saw it in any place) reduce scripts size, anymore tips? Edited September 12, 2019 by Furzy Link to comment
Aimcac Posted September 12, 2019 Share Posted September 12, 2019 Limit usage of createTimer, use getTickCount instead. Always localize variables i.e local x = 1 when required Always check arguments are met/set and use return when necessary to as to ensure a long function isn't carried out only to give an error in the end. Link to comment
Furzy Posted September 12, 2019 Author Share Posted September 12, 2019 34 minutes ago, Aimcac said: Limit usage of createTimer, use getTickCount instead. Always localize variables i.e local x = 1 when required Always check arguments are met/set and use return when necessary to as to ensure a long function isn't carried out only to give an error in the end. what the best way? setElementData(player,"value",1) data = {} for k,v in ipairs(data) do table.insert(k,v) end just example i know its not right Link to comment
Moderators IIYAMA Posted September 12, 2019 Moderators Share Posted September 12, 2019 2 hours ago, Furzy said: what the best way? There is no best way. Just be aware of the large amount of downsides of elementdata. Elementdata is nice for some functionalities, but do not use it when you have a scenario where it's features are not being used. Tables are pure for storing data on a player his computer. This data type only exist within a specific resource. It is very fast and clean. And cleans itself after the resource has stopped. Elementdata is a feature, that allows you to bind data on to an element. This data is available on all resources as it has left the Lua environment. Because the data leaves the Lua environment, it is not deleted when the resource stops. It is only deleted when the element is destroyed or when it is manually removed. By default this data is also shared with the server and all other players. Great! (if you want that) > Note: it can also quickly take over a large part of the network bandwidth when over using it. (results in Lag) But luckily it is possible to not share it with the server and the other players. bool setElementData ( element theElement, string key, var value [, bool synchronize = true ] ) Turn that OFF, by set it to false. Be aware: by default it is ON. Another benefit as well as a disadvantage is that element data has it's own event: https://wiki.multitheftauto.com/wiki/OnElementDataChange https://wiki.multitheftauto.com/wiki/OnClientElementDataChange Which gets triggered when the data changes. It is a nice feature, but it also uses a lot of performance. My recommendation Do only pick elementdata when you specific need to bind data to an element to SHARE it with another resource or other players. Do not over use elementdata. Be aware that elementdata is not data stored in your resource, but bound to your elements. Use tables everywhere you do no have to rely of elementdata features. Most of the time a triggerServerEvent is enough to share data with the server. Elementdata is a wild card. 1 Link to comment
Furzy Posted September 12, 2019 Author Share Posted September 12, 2019 6 minutes ago, IIYAMA said: There is no best way. Just be aware of the large amount of downsides of elementdata. Elementdata is nice for some functionalities, but do not use it when you have a scenario where it's features are not being used. Tables are pure for storing data on a player his computer. This data type only exist within a specific resource. It is very fast and clean. And cleans itself after the resource has stopped. Elementdata is a feature, that allows you to bind data on to an element. This data is available on all resources as it has left the Lua environment. Because the data leaves the Lua environment, it is not deleted when the resource stops. It is only deleted when the element is destroyed or when it is manually removed. By default this data is also shared with the server and all other players. Great! (if you want that) > Note: it can also quickly take over a large part of the network bandwidth when over using it. (results in Lag) But luckily it is possible to not share it with the server and the other players. bool setElementData ( element theElement, string key, var value [, bool synchronize = true ] ) Turn that OFF, by set it to false. Be aware: by default it is ON. Another benefit as well as a disadvantage is that element data has it's own event: https://wiki.multitheftauto.com/wiki/OnElementDataChange https://wiki.multitheftauto.com/wiki/OnClientElementDataChange Which gets triggered when the data changes. It is a nice feature, but it also uses a lot of performance. My recommendation Do only pick elementdata when you specific need to bind data to an element to SHARE it with another resource or other players. Do not over use elementdata. Be aware that elementdata is not data stored in your resource, but bound to your elements. Use tables everywhere you do no have to rely of elementdata features. Most of the time a triggerServerEvent is enough to share data with the server. Elementdata is a wild card. Thanks!! Link to comment
Scripting Moderators ds1-e Posted September 13, 2019 Scripting Moderators Share Posted September 13, 2019 6 hours ago, Furzy said: Thanks!! You might check that: https://springrts.com/wiki/Lua_Performance Loops, localize variables, unpack, and much more. I don't recommend to use ipairs at all. Int loop is much faster. 1 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now