nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.24k stars 29.41k forks source link

build node.js using clangcl when under Windows #52809

Open lemire opened 5 months ago

lemire commented 5 months ago

Description

Chrome and Firefox are built with Clang under Windows.

@targos made it possible to build Node.js using clang under Windows, see https://github.com/nodejs/node/pull/35433

At least in some tests, this seems to result in better performance:

                                                          confidence improvement accuracy (*)    (**)    (***)
v8\get-stats.js n=1000000 method='getHeapSpaceStatistics'                 3.36 %      ±10.99% ±14.62%  ±19.03%
v8\get-stats.js n=1000000 method='getHeapStatistics'                     10.35 %      ±10.90% ±14.50%  ±18.87%
v8\serialize.js n=1000000 len=16384                                       1.97 %       ±2.21%  ±3.14%   ±4.53%
v8\serialize.js n=1000000 len=256                                ***      5.59 %       ±1.61%  ±2.30%   ±3.36%
v8\serialize.js n=1000000 len=524288                                     19.28 %      ±48.92% ±76.74% ±130.72%

It is only preliminary, but it is not very difficult to conduct a full examination. There are some maintenance benefits to switching to LLVM under Windows as well. I stress that Node works right now under Windows when compiled with LLVM (credit to @targos).

There is at least one minor issue with ICU: https://github.com/nodejs/node/issues/34201 A tiny patch might be required. I actually expect that it might be the only problem.

I am opening this issue following a request by @mcollina

Further reading: Should Node.js be built with ClangCL under Windows?

Checklist:

mcollina commented 5 months ago

I recall that it was recommended by MS folks to build using clang on Windows.

lemire commented 5 months ago

One issue to consider is that Google switched over so they are developing V8 under ClangCL.

StefanStojanovic commented 5 months ago

I was thinking about opening an umbrella issue with a checklist or something like that for all things related to enabling ClangCL compilation on Windows, but since there is already this issue if you agree @lemire we can use it for that (if not, I'll create a separate issue with the content of this message).

Anyway, the following is (not sorted according to priority) a list of things done, being worked on, or that should be worked on before stating ClangCL is officially supported for compiling Node.js on Windows:

I might have missed something, but most things should be covered here. If anyone notices something missing or wrong, please let me know.

cc: @targos @nodejs/platform-windows

lemire commented 5 months ago

@StefanStojanovic It definitively makes sense to leverage the current issue.

StefanStojanovic commented 5 months ago

@StefanStojanovic It definitively makes sense to leverage the current issue.

Great! One issue I see with it is that if the comment gets edited often (eg. I edited it just now to add a PR I opened) it will probably not be sent as a notification, plus I'm probably the only one who can edit it. If anyone has a better idea eg. a GitHub Project or something like that, I'm all for it.

lemire commented 5 months ago

@StefanStojanovic I can edit your comment, but another take on it would be to edit the issue first post (that is, the text I have written). Do you have edit access?

I think you should be able to edit the issue... I think you have access... don't you?

That is, I don't own this issue, it should be a collective one.

StefanStojanovic commented 5 months ago

@StefanStojanovic I can edit your comment, but another take on it would be to edit the issue first post (that is, the text I have written). Do you have edit access?

I think you should be able to edit the issue... I think you have access... don't you?

That is, I don't own this issue, it should be a collective one.

Nope, I do not see edit. This is what I see. Not sure GH supports collective issues, would be great if it did...

image

lemire commented 5 months ago

@joyeecheung Can you help? I think we would like @StefanStojanovic to have the ability to edit this issue.

H4ad commented 5 months ago

@lemire He will have the ability to edit once he becomes a nodejs collaborator (probably next week)

lemire commented 5 months ago

@StefanStojanovic Given @H4ad's answer, I recommend just waiting a week or so. ;-)

hocheung-chromium commented 4 months ago

https://issues.chromium.org/issues/341803745

fp16 in v8 has been updated to the latest version, I think the blocker on the v8 side can be removed.

joyeecheung commented 3 months ago

If there are no reasons not to, switch to using ClangCL as a default compiler for future releases - Potentially Node.js v23 would be a nice time to do this.

We should probably update this point since V8 announced that they will drop MSVC support in September: https://groups.google.com/g/v8-dev/c/8mSxb2UriSU

StefanStojanovic commented 1 month ago

Hey everyone, while we're waiting for the ICU fix to get ported to Node, I just wanted to share with you the results of performance benchmarks I ran with ClangCL compiled binaries compared to MSVS ones (both compiled and ran locally). I used 10 runs to limit the execution to roughly a weekend. Once we can compile with ClangCL in CI I will use one of the CI machines to run even more benchmarks there.