Jump to content

Server optimization


Furzy

Recommended Posts

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
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:

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 1
Link to comment
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:

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...