Just want to get this out for all the people who seem to be unaware and just clutter their exports/events.
ReadMe
Down below are the files for two resources servemaster and askingforit.
servemaster just returns a string of one character repeated n-times.
Executing these shows that sending too much data through exports/events, will cause your server to hitch.
It will show up as a high tick rate for the sending resource, even tho the resource finished its code, execution within less of a millisecond.
Starting a data transfer rate (at my local pc) of 1MB/s I start getting hitches, above 100kB/s the sending times start spiraling out of control.
Conclusions for developers
With a growing number of players thanks to OneSync on your servers, you should follow some basic principles.
Send only necessary data through exports/events.
Send static data via JSON files to users, load these JSON files from other resources instead of accessing data via exports/events
Avoid sending entire objects through exports like ESX does.
Very intereseting but I have a couple of questions though:
Doesn’t ESX pass his objects by reference? And passing by reference would be fast right?
What I see a lot is: TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end).
Is there any performance difference between using a export or a event? Should I just always use one or the other?
I’m not sure on the details, afaik functions are passed by reference, but all variables seems to be passed by value, cause if you load the playerdata table on first spawn, the data won’t be updated.
Talking about events/exports, they should be the same thing, but then again i’m not sure. From what I know exports are just syntactic sugar to use events in a synchronous way.
I see, luckily I already do that, I’ve never understood why most scripters put static data in the DB anyway. For static data I mainly use lua tables that are shared by both client and server, are there any performance benefits in using a JSON file instad of a Lua table?