citizenfx / fivem

The source code for the Cfx.re modification frameworks, such as FiveM, RedM and LibertyM, as well as FXServer.
https://cfx.re/
3.47k stars 2.05k forks source link

Add NodeJS v20 script runtime #2479

Open martonp96 opened 4 months ago

martonp96 commented 4 months ago

Goal of this PR

The goal of this PR is to add a new NodeJS v20 script runtime, so developers can experiment and migrate their server scripts to a newer version, enabling them to have the up-to-date NodeJS experience.

How is this PR achieving the goal

By creating a new server side component, so old and new node runtimes can work independently side by side. Most of the code is reused from the old runtime in a well organized manner.

This PR applies to the following area(s)

Server, ScRT: Node

Successfully tested on

Windows, Linux

Platforms: Windows, Linux

Checklist

blattersturm commented 4 months ago

A "high frequency tick method" dedicated to pumping every Node resource's uv loop (even worse if it also runs the main scheduler tick!) is not the way to go here either. People at times run hundreds of resources, and this runs counter to e.g. the tickless work done prior, even though this was meant to focus on client performance, the same would apply to server-side overhead.

Tight coupling to reduce ScRT enumeration/tick overhead still adds per-runtime cost, makes a mess of the code, and still adds timer overhead/delay since event signaling is not timer-bound at all. There really isn't any way to cheap out of something like the EnvironmentScope stuff, unless upstream nowadays has something like this via e.g. async hooks. If maintaining this patch set is problematic, consider suggesting this use case to upstream Node.js maintainers instead, given it's a common embedder use case to wish to embed in an existing libuv event loop (and the uv dependency isn't the painful one to wish to sync with upstream- it's the v8 one).

Perhaps a cheap trick could be to somehow hoist events from the Node.js event loop into the server event loop and wrap callbacks that way rather than patching Node.js to enter/exit environments cleanly on callbacks.

SymbianMoe commented 4 months ago

finally <3

Yum1x commented 4 months ago

@martonp96 do you have plans to implement Node 22? it'll also be LTS

martonp96 commented 4 months ago

@martonp96 do you have plans to implement Node 22? it'll also be LTS

@Yum1x yes, its planned when it becomes LTS officially

DigitalWolf98 commented 1 month ago

Hi all, I know that the question will sound a bit silly, but I'll ask it nevertheless - Does anyone know when there will be an update with Node.js (a specific release date, month or year) to understand exactly whether it is worth waiting for it in the near future ? Everywhere I asked the question, answered something like "in the near future will be...", but this answer is not satisfactory because there are teams of developers who seriously want to open their own project, and even formalize the official documents to open a sole proprietorship, which entails financial costs even for such a case as this, which makes the business idle.

DaniGP17 commented 1 month ago

Does anyone know when there will be an update with Node.js

In the experimental section of the forum they said: "Currently we are planning to investigate issue with performance when writing to statebags and then looks like nothing prevent us from pushing this to Canary."

DigitalWolf98 commented 1 month ago

Well again, even you said the phrase "In the near future, something will happen there", so this near future has already lasted long enough, if you take ES6 and specificallyimport/export the implementation in Node.js, it appeared in version 12.0.0, which was released on April 23, 2019. But in FiveM this "functionality" is cut out for some reason, leaving only the error throwing - TypeError: Invalid host defined options.