Skip to content
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,win: configuration tweaks for faster build with MSVC #25931

Merged
merged 7 commits into from
Feb 14, 2019

Conversation

refack
Copy link
Contributor

@refack refack commented Feb 4, 2019

Several optimization to reduce build time on Windows.

  1. Run link-time optimizations and codegen only for the node.exe target.
  2. Add more .h files to pch for V8
  3. Use V8 pch with more targets
  4. Add configuration to use pch while building node code
  5. Set to always use pch.
    IIUC the reason not to build V8 with pch was as not to diverge, but V8 is anyway built with clang_cl and not with the MSVC compiler, so divergence exists anyway.

Total build time on https://ci.nodejs.org/computer/test-rackspace-win2008r2-x64-3/:

Minutes PR master
release, no pch 22:56 46:10
"dev mode" - no pch, no LTCG 10:06 12:08
release with pch 10:18 -

/CC @nodejs/build-files @nodejs/platform-windows @nodejs/v8-update

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@refack refack added windows Issues and PRs related to the Windows platform. build Issues and PRs related to build files or the CI. v8 engine Issues and PRs related to the V8 dependency. gyp Issues and PRs related to the GYP tool and .gyp build files labels Feb 4, 2019
@refack refack self-assigned this Feb 4, 2019
@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Feb 4, 2019
@refack
Copy link
Contributor Author

refack commented Feb 4, 2019

P.S. this also reduce divergence between "dev" builds (no LTCG) and "release" builds (with LTCG), as now they both use pch.

@refack
Copy link
Contributor Author

refack commented Feb 5, 2019

@refack
Copy link
Contributor Author

refack commented Feb 5, 2019

Copy link
Member

@joaocgreis joaocgreis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was not using PCH by default as it carries some risk. It makes the build very different from other platforms (the headers are the same for all files, ignoring defines) and gives the compiler different opportunities for optimization. Since now it has been in use for some time, it's probably a good time to make it default.

deps/v8/gypfiles/v8.gyp Outdated Show resolved Hide resolved
deps/v8/gypfiles/v8.gyp Outdated Show resolved Hide resolved
src/node_pch.cc Outdated Show resolved Hide resolved
src/node_pch.h Outdated
@@ -0,0 +1,15 @@
#pragma once
#define NAPI_EXPERIMENTAL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this always safe? I see in some files where this is defined other headers are included before. With this here, NAPI_EXPERIMENTAL will always be defined, can probably be removed from everywhere in the code.

There is also NODE_WANT_INTERNALS. There is and explicit define in inspector_socket.cc which will be ignored by all headers pulled by these here.

This might be safe, but is not obvious to me. Might also become difficult to maintain, since anyone not using Windows will only see errors when running CI (if at all).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@joaocgreis
Copy link
Member

This should probably be semver major to be safe. I don't expect anything to break, but wouldn't be surprised if there were differences compiling modules or with performance. In my benchmarking of the PCH we have now, I noticed somethings were faster and some slower, by small margins, and I'm not sure how conclusive that was.

@bzoz can you take a look at the linking changes here?

@joaocgreis joaocgreis added the semver-major PRs that contain breaking changes and should be released in the next major version. label Feb 5, 2019
@refack refack force-pushed the msvs-speed-tweaks branch 3 times, most recently from 395d5a1 to cfbde88 Compare February 5, 2019 23:12
@refack
Copy link
Contributor Author

refack commented Feb 6, 2019

Very rough comparison

Baseline:
image

PR:
image

@gengjiawen
Copy link
Member

So on windows run vcbuild.bat will be much more faster after this patch get merged, right ?

@refack
Copy link
Contributor Author

refack commented Feb 6, 2019

So on windows run vcbuild.bat will be much more faster after this patch get merged, right ?

🤞 that's the dream

Copy link
Member

@joaocgreis joaocgreis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but it'd be good to have confirmation that there's no issue with the NODE_WANT_INTERNALS define in inspector_socket.cc. Thanks @refack!

@refack
Copy link
Contributor Author

refack commented Feb 14, 2019

Since there should not be any explicit breaking changes, maybe we can commute the semver-major to dont-land-on-*?

/CC @nodejs/tsc

tl;dr this cuts build time on Windows by ~70%

@targos
Copy link
Member

targos commented Feb 14, 2019

Since there should not be any explicit breaking changes, maybe we can commute the semver-major to dont-land-on-*?

SGTM

@joaocgreis joaocgreis added dont-land-on-v6.x and removed semver-major PRs that contain breaking changes and should be released in the next major version. labels Feb 14, 2019
@joaocgreis
Copy link
Member

SGTM. I added it, so I went ahead and changed it. Actually only the commit build,win: always build with PCH should be affected by this, and that only preemptively.

@refack
Copy link
Contributor Author

refack commented Feb 14, 2019

* ASCIIbetize directives
* Merge duplicate directives from 'conditions'

PR-URL: nodejs#25931
Reviewed-By: João Reis <reis@janeasystems.com>
* Use relative path for easy reuse in other projects

PR-URL: nodejs#25931
Reviewed-By: João Reis <reis@janeasystems.com>
* rename files to represent reuse

PR-URL: nodejs#25931
Reviewed-By: João Reis <reis@janeasystems.com>
PR-URL: nodejs#25931
Reviewed-By: João Reis <reis@janeasystems.com>
PR-URL: nodejs#25931
Reviewed-By: João Reis <reis@janeasystems.com>
PR-URL: nodejs#25931
Reviewed-By: João Reis <reis@janeasystems.com>
PR-URL: nodejs#25931
Reviewed-By: João Reis <reis@janeasystems.com>
@deepak1556
Copy link
Contributor

deepak1556 commented Oct 9, 2019

@refack this change moved the configuration of node_with_ltcg from common.gypi to node.gyp , so native addons built from node-gyp no longer get the configuration as result leads to increase in size. The following observation was made with node v12.4.0

Without ltcg (current change):

Screenshot (10)

With ltcg added to node-gyp addon.gypi:

Screenshot (9)

Would it make sense to add this definition to node-gyp rather than common.gypi so that even Electron and other embedders could benefit from this ? Thanks!

This was found while investigating electron/electron#18670

@Trott
Copy link
Member

Trott commented Oct 10, 2019

@nodejs/platform-windows @nodejs/node-gyp @nodejs/embedders

@richardlau
Copy link
Member

Discussion is in #29501.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. gyp Issues and PRs related to the GYP tool and .gyp build files lib / src Issues and PRs related to general changes in the lib or src directory. v8 engine Issues and PRs related to the V8 dependency. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants