Be aware: Hitches from sending a lot of data between resources (server-side)

Just want to get this out for all the people who seem to be unaware and just clutter their exports/events.


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.
1 Like

Very intereseting but I have a couple of questions though:

  1. 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).
  2. Is there any performance difference between using a export or a event? Should I just always use one or the other?
1 Like

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.

How would you do that? Code a custom resource that uses a websocket to send the data or just encode the object?

What I think he means is something like @Woopi posted here but I am not sure: [How to] JSON with FiveM

I mean you send static data (non-critical data) via the files in the fxmanifest.lua, directly to the client.

And load them client-side, instead of fetching them on the server from DB, and sending them then to each client.

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?