-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: use more aggressive LTO on gcc #56138
Conversation
Review requested:
|
cc @nodejs/build @nodejs/performance please take a look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm.
Just as a question, do we distribute binaries built w/ gcc?
Yes, I think so, but @nodejs/build can answer this better than me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you measured it in different environments?
Only macOS for now. I can measure it on Linux tomorrow, if someone doesn't beat me to it. Please run and share outputs from your machine regardless. Let's make sure the numbers are correct. |
I can test linux in a couple hours |
You build with gcc on macOS? 🧐 |
I know nothing about LTO |
@@ -13,6 +13,7 @@ | |||
'enable_pgo_generate%': '0', | |||
'enable_pgo_use%': '0', | |||
'python%': 'python', | |||
'enable_lto': 'true', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this bypasses / overrides the --enable-lto
configure flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, yeah this should just flip the flag in configure.py, at least flip it to true on known safe platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think this gets overridden by the config.gypi
generated by ./configure
, so it's not actually enabling LTO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried enabling it with --enable-lto and it in fact took longer than the current build, but it didn't take forever to link mkdsnapshot. It took longer but it finished. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be that you Mac is beefier than mine/your lld is newer than mine/you just have more patience than I do ;) (I think I waited for ~20 minutes before I gave up)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably. I have the new mac mini with the highest spec.
@joyeecheung The improvements on macOS probably come from |
If -ffunctions and -fdata-sections is passed, should be not also --gc-sections passed to the linker? |
So I tried building with Which now reminds me, we need to disable ICF for both node_mksnapshot and v8's mksnapshot, because otherwise the external references may not match after functions are folded and the program may crash. Which means porting this Lines 7351 to 7366 in 5ab3140
To the gyp configs. (IIRC windows enables LTO + ICF and it seems to have no problem, but maybe I am reading it wrong, but anyway it can be risky not to disable it) |
Yes :-) |
I tried building this PR locally on macOS, and AFAICT, it doesn't enable LTO.
And the
Whereas when I actually build the main branch with
|
https://github.com/nodejs/node/blob/main/BUILDING.md#official-binary-platforms-and-toolchains Lines 158 to 190 in c4aa34a
|
Re. LTO, we currently do not have that enabled by default on the official binaries. Anecdotally, I understand that downstream Fedora/RHEL Node.js had to turn off LTO due to the increased memory requirements/build times with it enabled. There's also #49063, which may help. |
So I gave it a bit more patience and managed to build the main branch with Locally it doesn't look like LTO makes much of a difference on macOS despite waiting for more than half of an hour to build...
Also to my surprise, binary size is bigger after LTO?!
|
I tried enabling PGO as well, and it didn't make a difference at all. Maybe we are missing something @joyeecheung |
@ptr1337 I found some examples of |
Using more aggressive LTO, the startup time of Node.js can be reduced from 38ms to 28ms.
Before
After