Should Node.js be built with ClangCL under Windows?

https://lemire.me/blog/2024/05/02/should-node-js-be-built-with-clangcl-under-windows/

Under Windows, when using Visual Studio to build C++ code, there are two possible compiler strategies. The Visual Studio compiler (often referred to as MSVC) is the default compiler provided by Microsoft for Windows development. In Debug mode, the regular Visual Studio compiler produces faster compilation times and more performant code compared to ClangCL. ClangCL is part of the Clang/LLVM project, which is an open-source compiler toolchain. ClangCL is compatible with the Visual Studio runtime and links with the Microsoft implementation of the Standard Library. It’s available as an optional component in Visual Studio 2019 and later versions.

In Debug mode, I find that the regular Visual Studio compiler builds faster. However, in release mode, I found empirically that ClangCL approach may provide more performant code. On some micro-benchmarks, the difference can be large (e.g., 40%) although I expect more modest gains on complex systems.

As of Chrome 64, Google Chrome for Windows is compiled with ClangCL. Thus Clang is now used to build Chrome for all platforms it runs on, including macOS, iOS, Linux, Chrome OS, Android, and Windows. Firefox switched to ClangCL in 2018. And at least some game developers have adopted ClangCL.

Node.js is an open-source, cross-platform JavaScript runtime environment. It allows developers to execute JavaScript code outside of a web browser. Unlike traditional JavaScript, which primarily runs in browsers, Node.js enables server-side execution of JavaScript. Node.js is part of popular web development stacks Node.js relies on the Google Chrome V8 JavaScript Engine: Node.js is built on the V8 JavaScript engine, the same engine used by Google Chrome.

Node.js is built under Windows using the regular Visual Studio compiler. Thanks in large part to Michaël Zasso, it is possible to build the Node.js under Windows with ClangCL. Could it improve the performance?

To start answering this question, I ran the standard V8 benchmarks from Node.js. These benchmarks mostly focus on V8 performance and are not affected by changes in other components. For my tests, I use Visual Studio 2022 on Microsoft Surface Laptop Studio.

All results point at improvements. That is, on average, the speed is greater with ClangCL than using the standard Visual Studio compiler. However, there is much noise in my numbers. Using the V8 benchmarks, only one test was statistically strong (serialize.js len=256).

function improvement
v8\get-stats getHeapSpaceStatistics 3% +/- 11%
v8\get-stats getHeapStatistics 10% +/- 11%
v8\serialize.js len=256 6% +/- 2%
v8\serialize.js len=16384 2% +/- 2%
v8\serialize.js len=524288 19% +/- 50%

I should stress that compilers have strengths and weaknesses. The regular Visual Studio compiler is perfectly capable and you should expect it to do better in some instances. And Microsoft have some of the best compiler engineers in the world: each new version might bring in improvements.

Furthermore, some tasks and benchmarks are not necessarily affected by the choice of a compiler: e.g., a network access, a disk processing routine, or a memory allocation stress test.

Yet it appears that there might be benefits to a transition to ClangCL for Node.js.

Post navigation

{
"by": "mariuz",
"descendants": 1,
"id": 40240624,
"kids": [
40260011
],
"score": 11,
"time": 1714679090,
"title": "Should Node.js be built with ClangCL under Windows?",
"type": "story",
"url": "https://lemire.me/blog/2024/05/02/should-node-js-be-built-with-clangcl-under-windows/"
}
{
"author": "View all posts by Daniel Lemire",
"date": "2024-05-01T12:00:00.000Z",
"description": null,
"image": "https://secure.gravatar.com/avatar/2ca999bef9535950f5b84281a4dab006?s=56&d=mm&r=g",
"logo": "https://logo.clearbit.com/lemire.me",
"publisher": "Daniel Lemire",
"title": "Should Node.js be built with ClangCL under Windows? – Daniel Lemire’s blog",
"url": "https://lemire.me/blog/2024/05/02/should-node-js-be-built-with-clangcl-under-windows/"
}
{
"url": "https://lemire.me/blog/2024/05/02/should-node-js-be-built-with-clangcl-under-windows/",
"title": "Should Node.js be built with ClangCL under Windows? – Daniel Lemire's blog",
"description": "Under Windows, when using Visual Studio to build C++ code, there are two possible compiler strategies. The Visual Studio compiler (often referred to as MSVC) is the default compiler provided by Microsoft for...",
"links": [
"https://lemire.me/blog/?p=21309",
"https://lemire.me/blog/2024/05/02/should-node-js-be-built-with-clangcl-under-windows/"
],
"image": "",
"content": "<div>\n<article>\n<div>\n<p>Under Windows, when using Visual Studio to build C++ code, there are two possible compiler strategies. The Visual Studio compiler (often referred to as MSVC) is the default compiler provided by Microsoft for Windows development. In Debug mode, the regular Visual Studio compiler produces faster compilation times and more performant code compared to ClangCL. ClangCL is part of the Clang/LLVM project, which is an open-source compiler toolchain. ClangCL is compatible with the Visual Studio runtime and links with the Microsoft implementation of the Standard Library. It’s available as an optional component in Visual Studio 2019 and later versions.</p>\n<p>In Debug mode, I find that <a target=\"_blank\" href=\"https://lemire.me/blog/2023/02/27/visual-studio-versus-clangcl/\">the regular Visual Studio compiler builds faster</a>. However, in release mode, I found empirically that ClangCL approach may provide more performant code. On some micro-benchmarks, the difference can be large (e.g., 40%) although I expect more modest gains on complex systems.</p>\n<p>As of Chrome 64, Google Chrome for Windows is compiled with ClangCL. Thus Clang is now used to build Chrome for all platforms it runs on, including macOS, iOS, Linux, Chrome OS, Android, and Windows. <a target=\"_blank\" href=\"https://groups.google.com/g/mozilla.dev.platform/c/wwO48xXFx0A\">Firefox switched to ClangCL</a> in 2018. And at least some game developers have adopted ClangCL.</p>\n<p>Node.js is an open-source, cross-platform JavaScript runtime environment. It allows developers to execute JavaScript code outside of a web browser. Unlike traditional JavaScript, which primarily runs in browsers, Node.js enables server-side execution of JavaScript. Node.js is part of popular web development stacks Node.js relies on the Google Chrome V8 JavaScript Engine: Node.js is built on the V8 JavaScript engine, the same engine used by Google Chrome.</p>\n<p>Node.js is built under Windows using the regular Visual Studio compiler. Thanks in large part to Michaël Zasso, it is possible to build the Node.js under Windows with ClangCL. Could it improve the performance?</p>\n<p>To start answering this question, I ran the standard V8 benchmarks from Node.js. These benchmarks mostly focus on V8 performance and are not affected by changes in other components. For my tests, I use Visual Studio 2022 on Microsoft Surface Laptop Studio.</p>\n<p>All results point at improvements. That is, on average, the speed is greater with ClangCL than using the standard Visual Studio compiler. However, there is much noise in my numbers. Using the V8 benchmarks, only one test was statistically strong (serialize.js len=256).</p>\n<table>\n<tbody>\n<tr>\n<th>function</th>\n<th>improvement</th>\n</tr>\n<tr>\n<td>v8\\get-stats getHeapSpaceStatistics</td>\n<td>3% +/- 11%</td>\n</tr>\n<tr>\n<td>v8\\get-stats getHeapStatistics</td>\n<td>10% +/- 11%</td>\n</tr>\n<tr>\n<td><strong>v8\\serialize.js len=256</strong></td>\n<td><strong>6% +/- 2%</strong></td>\n</tr>\n<tr>\n<td>v8\\serialize.js len=16384</td>\n<td>2% +/- 2%</td>\n</tr>\n<tr>\n<td>v8\\serialize.js len=524288</td>\n<td>19% +/- 50%</td>\n</tr>\n</tbody>\n</table>\n<p>I should stress that compilers have strengths and weaknesses. The regular Visual Studio compiler is perfectly capable and you should expect it to do better in some instances. And Microsoft have some of the best compiler engineers in the world: each new version might bring in improvements.</p>\n<p>Furthermore, some tasks and benchmarks are not necessarily affected by the choice of a compiler: e.g., a network access, a disk processing routine, or a memory allocation stress test.</p>\n<p>Yet it appears that there might be benefits to a transition to ClangCL for Node.js.</p>\n </div>\n<div>\n<p><img src=\"https://secure.gravatar.com/avatar/2ca999bef9535950f5b84281a4dab006?s=56&amp;d=mm&amp;r=g\" srcset=\"https://secure.gravatar.com/avatar/2ca999bef9535950f5b84281a4dab006?s=112&amp;d=mm&amp;r=g 2x\" /> </p>\n</div>\n</article>\n<h2>Post navigation</h2>\n</div>",
"author": "",
"favicon": "https://lemire.me/blog/wp-content/uploads/2015/10/profile2011_152.jpg",
"source": "lemire.me",
"published": "",
"ttr": 100,
"type": ""
}