Hello people,
why is the performance of JavaScript so bad/slow compared to Lua? Am I making a mistake or what is the reason?
Example:
I made a small script who trigger the ESX sharedobject and print it in the console.
The Script in LUA:
ESX = nil
Citizen.CreateThread(function()
while not ESX do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(500)
end
end)
Citizen.CreateThread(function()
while true do
print(ESX)
Citizen.Wait(100)
end
end)
The Script in JavaScript:
let ESX = null;
Wait = (ms) => new Promise(resolve => setTimeout(resolve, ms))
setTick(async () => {
if (!ESX) {
emit(`esx:getSharedObject`, obj => ESX = obj)
}
await Wait(500)
})
setTick(async () => {
print(ESX)
await Wait(100)
})
The Lua Script needs 0.01 - 0.02ms but the JavaScript needs 0.04 - 0.06ms and jumps at the start even to 0.70ms. When i replace all setTick with setInterval and remove all Wait functions. It needs even 0.06 - 0.07ms
Is JavaScript really so slow?