citizenfx/cfx-server-data

Chat Resource takes longer to load the more scripts you have.

P4R4NORM4L opened this issue · 4 comments

After some debugging I've found that the more resources you load, the slower will be the ui to be ready (and chat)

So this client side code:
`
AddEventHandler('onClientResourceStart', function(resName)
Wait(500)

refreshCommands()
refreshThemes()
end)
`

will call that 2 functions each time a resource is loaded and so it will send NUIs data to update each suggestion and theme for every resource that is loaded and the UI hung for a few seconds after player loads the char and suddenly, all notifications and the chat, appers. On older PCs may take up to 30seconds after the player loaded to 'enable' the UI

The problem is that the previous version, before v2, does the same thing but doesn't hang the UI so it can process a lot fast the incoming messages. What is wrong or different since you've changed to v2? Is the compile method?

One fix that I've done and helped a lot was:
creating a
local playerLoaded = false

then
onClientResourceStart and onClientResourceStop, the refreshCommands() and refreshThemes() i put it inside a if playedLoaded

then added

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
playerLoaded = true
end)

and on

RegisterNUICallback('loaded', function(data, cb)
TriggerServerEvent('chat:init')

while not playerLoaded do Wait(500) end

refreshCommands()

refreshThemes()

chatLoaded = true

cb('ok')
end)
And solved. What does it do? Well, only when the player is loaded if will update commands and themes, just once.
And maintain the functionality that on a resource stop or start it updates the commands and themes like before.

Maybe there's a more efficient solution to stop the loop between all sending commands and themes as much as the number of resources loaded, but it works and works well

Yes sure, but this script is not efficient. If you have 200 scripts loading, you will repeat a loop that will iterate from 200 scripts, check what scripts are started and send nui's for each command registed.
It's simple, just put a print before the NUI call inside refreshCommands() function and see the huge inefficency by itself, repeating and repeating same stuff over N resources loaded, instead of doind that only 1 time, after player is loaded and all resources loaded.

This is not a workaround this is a solution to prevent overhead of repetitive NUIs doing the same thing over and over for every script that is loading.
In Discord of CFX we can see a lot of people telling that chat have a slow loading. (who uses this V2, because most people uses the previous version that doesn't have that problem)

@blattersturm I redid this thread as I don't think it's fair to @fcatalao for closing the issue before it was resolved.

Acting like this doesn't help. Posting misinformation on other issues, same.

You have just gotten yourself a block, and another closed issue.

Again, if anyone has any constructive information on issues like this, you're welcome, but pasting the same from the closed thread into a new issue is not constructive at all.