Scripts' performance - Lua vs JavaScript

Intro

I’m a Front End Developer for a living, so I started wondering, since I use JavaScript (JS) on a daily basis, I could move from writing in Lua, to JS (maybe even TypeScript, cause I saw it’s possible).

I remember that the other day I tried to write some small script in JS, only to check how it works, but I stumbled upon one critical issue - performance.

The test script

So I went with a pretty “dummy” script, which was about having a marker drawn somewhere, some clicking functionality and some small backend actions (which are not relevant in this discussion).

One script was written in JS, and the other one (the same script), written in Lua.

When I compared both script in resmon, I realized that the JS one was much heavier on the CPU and memory.

Question

I’m wondering if maybe someone has experience with both Lua and JS, and could talk about it here - what’s the performance difference, etc. I didn’t have enough time to directly decide if JS really was slower or in general worse, but I’m looking for some input from the community.

1 Like

JS is slower then lua

JS isn’t slower than LUA. It got a little bit of overhead (even for empty resources) which I believe is a bug and may be fixed anytime soon. In any case your JS script will not get exponentially slower compared to you LUA script.

When it comes to choosing a language, I would recommend picking the one you want to learn (or master in case you aren’t interested in learning a language). As long as you code properly, you’ll not have any performance issues.

What do you think about C#? Is it significantly inferior in performance to Lua by fivem? I just can’t seem to solve the problem with the readings going off the charts when using Tick to draw markers or capture key presses

C# is not slower than lua and it’s one of the best language to master right now if you’re a backend developer.
Lua is a cool language really simple to master, but it’s not used a lot and have a bad class system.
Typescript / JavaScript is one of the best frontend language, but it’s not good in term of performance, but for FiveM development it will works.

So the question is precisely that Sharp himself is cool. but at fivem it consumes resources. or rather basescript.tick eats them. How to deal with this, is there any advice?

Example

I haven’t developed in Csharp on fivem for over 2 years (because 99% of the community is on lua instead), I saw a news at least 6 months ago where FiveM announced it had fixed these performance problems.
We’d have to do some testing to verify this, the worst thing is that part of FiveM is coded in Csharp so it should be well integrated normally.

Unfortunately, either I’m doing something wrong or nothing has been fixed.

I spent a huge amount of time developing my server almost from scratch, but it’s impossible to use because of the freezes