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: add flag to enable pointer compression #30463

Closed
wants to merge 1 commit into from

Conversation

mcollina
Copy link
Member

This PR adds support for building node with pointer compression enabled. From some preliminary tests, enabling pointer compression shrinks memory usage by 40%.

See: #26756

Note that building with this flag makes some of our addon tests fail:

=== release test ===
Path: addons/async-hooks-promise/test
Command: out/Release/node /home/matteo/repositories/node/test/addons/async-hooks-promise/test.js
--- CRASHED (Signal: 11) ---
=== release test ===
Path: addons/08_passing_wrapped_objects_around/test
Command: out/Release/node /home/matteo/repositories/node/test/addons/08_passing_wrapped_objects_around/test.js
--- CRASHED (Signal: 11) ---
=== release test ===
Path: addons/new-target/test
Command: out/Release/node /home/matteo/repositories/node/test/addons/new-target/test.js
--- CRASHED (Signal: 11) ---
=== release test ===
Path: addons/make-callback/test
Command: out/Release/node /home/matteo/repositories/node/test/addons/make-callback/test.js
--- CRASHED (Signal: 11) ---
=== release test ===
Path: addons/06_wrapping_c_objects/test
Command: out/Release/node /home/matteo/repositories/node/test/addons/06_wrapping_c_objects/test.js
--- CRASHED (Signal: 11) ---
=== release test ===
Path: addons/07_factory_of_wrapped_objects/test
Command: out/Release/node /home/matteo/repositories/node/test/addons/07_factory_of_wrapped_objects/test.js
--- CRASHED (Signal: 11) ---
=== release test-perf-hooks-timerify ===
Path: addons/non-node-context/test-perf-hooks-timerify
Command: out/Release/node /home/matteo/repositories/node/test/addons/non-node-context/test-perf-hooks-timerify.js
--- CRASHED (Signal: 11) ---
[02:41|% 100|+ 2807|-   7]: Done
Makefile:296: recipe for target 'jstest' failed
make[1]: *** [jstest] Error 1
Makefile:316: recipe for target 'test' failed
make: *** [test] Error 2
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the build Issues and PRs related to build files or the CI. label Nov 13, 2019
@mcollina
Copy link
Member Author

@addaleax
Copy link
Member

Note that building with this flag makes some of our addon tests fail:

Yeah, that’s expected. Enabling pointer compression changes the Node.js ABI, which is IIRC the reason why we haven’t done this so far.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

This needs a good story for our addon ABI

@codebytere
Copy link
Member

Electron feels similarly - the memory savings are positive especially considering they're per-isolate but we're concerned about ABI compat of native modules

@mcollina
Copy link
Member Author

@gabrielschulhof can you confirm n-api can handle this case?

@mcollina
Copy link
Member Author

This needs a good story for our addon ABI

@addaleax my goal for this is to make it easier for folks to experiment with address compression. If you are ok, I'll add the option as "(experimental)" in the ./configure help.

@addaleax
Copy link
Member

@gabrielschulhof can you confirm n-api can handle this case?

N-API is unaffected.

This needs a good story for our addon ABI

@addaleax my goal for this is to make it easier for folks to experiment with address compression. If you are ok, I'll add the option as "(experimental)" in the ./configure help.

That would be good, but I’d prefer to explicitly call out that this mode does not currently support addons (at all)?

@jasnell
Copy link
Member

jasnell commented Nov 14, 2019

Definite +1 on marking this experimental and documenting the impact on native addons. Assuming those changes, this LGTM

@hashseed
Copy link
Member

That would be good, but I’d prefer to explicitly call out that this mode does not currently support addons (at all)?

Yeah iirc the plan was to consider having a build flag in V8 that ensures ABI stability regardless of whether pointer compression is enabled or not, by sacrificing some performance, since inline-implemented APIs would need to be replaced by non-inline versions.

@mcollina
Copy link
Member Author

Updated @jasnell @addaleax

Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

would be good to enable so we can at least start playing with it

node.gyp Show resolved Hide resolved
@nodejs-github-bot
Copy link
Collaborator

@mcollina
Copy link
Member Author

mcollina commented Nov 22, 2019

I've removed the config from common.gypi. Please review.

cc @targos

@nodejs-github-bot
Copy link
Collaborator

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 30, 2019
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

configure.py Outdated Show resolved Hide resolved
@jasnell
Copy link
Member

jasnell commented Dec 1, 2019

I'm wondering whether there should be a warning printed at runtime when the node.js process starts.

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@tniessen tniessen left a comment

Choose a reason for hiding this comment

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

LGTM as an experimental build feature.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@mcollina
Copy link
Member Author

mcollina commented Dec 9, 2019

@nodejs/build @nodejs/testing I would need some help here, as tests that seems unrelated are failing, however this should not change the default config.

@nodejs-github-bot
Copy link
Collaborator

@BridgeAR
Copy link
Member

@mcollina we currently rarely have green builds. There are lots of infrastructure failures and flaky tests. That's what seemed to have happened here as well.

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Dec 10, 2019

@Trott Trott added the semver-minor PRs that contain new features and should be released in the next minor version. label Dec 10, 2019
@Trott
Copy link
Member

Trott commented Dec 12, 2019

Landed in 086c7b4

@Trott Trott closed this Dec 12, 2019
Trott pushed a commit to Trott/io.js that referenced this pull request Dec 12, 2019
The --experimental-enable-pointer-compression is experimental
as it breaks ABI compatibility.

PR-URL: nodejs#30463
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
MylesBorins pushed a commit that referenced this pull request Dec 13, 2019
The --experimental-enable-pointer-compression is experimental
as it breaks ABI compatibility.

PR-URL: #30463
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Dec 13, 2019
@mmarchini
Copy link
Contributor

@targos any concerns on backporting this to v12.x? I was testing it today, and if we add the following lines (pulled from dda658c) to common.gypi, it works:

diff --git a/common.gypi b/common.gypi
index 8c9076b735..856c6aa6ff 100644
--- a/common.gypi
+++ b/common.gypi
@@ -339,6 +339,12 @@
           }],
         ],
       }],
+      ['v8_enable_pointer_compression == 1', {
+        'defines': ['V8_COMPRESS_POINTERS'],
+      }],
+      ['v8_enable_pointer_compression == 1 or v8_enable_31bit_smis_on_64bit_arch == 1', {
+        'defines': ['V8_31BIT_SMIS_ON_64BIT_ARCH'],
+      }],
       ['OS == "win"', {
         'defines': [
           'WIN32',

The changes are non-intrusive, since it only impacts builds using --experimental-enable-pointer-compression. I can send a PR to backport it, unless there are other concerns.

@tuananh
Copy link
Contributor

tuananh commented Feb 23, 2020

where can i download a built version with --experimental-enable-pointer-compression enabled?

@mhdawson
Copy link
Member

@tuananh I believe you have to build it yourself as it is not in any of the shipping binaries.

@richardlau
Copy link
Member

@targos any concerns on backporting this to v12.x? I was testing it today, and if we add the following lines (pulled from dda658c) to common.gypi, it works:

diff --git a/common.gypi b/common.gypi
index 8c9076b735..856c6aa6ff 100644
--- a/common.gypi
+++ b/common.gypi
@@ -339,6 +339,12 @@
           }],
         ],
       }],
+      ['v8_enable_pointer_compression == 1', {
+        'defines': ['V8_COMPRESS_POINTERS'],
+      }],
+      ['v8_enable_pointer_compression == 1 or v8_enable_31bit_smis_on_64bit_arch == 1', {
+        'defines': ['V8_31BIT_SMIS_ON_64BIT_ARCH'],
+      }],
       ['OS == "win"', {
         'defines': [
           'WIN32',

The changes are non-intrusive, since it only impacts builds using --experimental-enable-pointer-compression. I can send a PR to backport it, unless there are other concerns.

If this does get backported it will need to land with #33688 to fix building addons.

@mmarchini
Copy link
Contributor

Probably not worth it. We have pointer compressions builds for v14 now, and the pointer compression implementation on v12 has bugs as well as performance issues.

richardlau added a commit to richardlau/node-1 that referenced this pull request Jun 4, 2020
`common.gypi` is used by `node-gyp` to compile addons. Default values
must be provided for variables that may not exist on older versions of
Node.js so that older versions of Node.js can be used to compile addons
for later versions of Node.js.

Add default values for `v8_enable_pointer_compression` and
`v8_enable_31bit_smis_on_64bit_arch`.

PR-URL: nodejs#33688
Refs: nodejs#30463
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Signed-off-by: Richard Lau <[email protected]>
codebytere pushed a commit that referenced this pull request Jun 18, 2020
`common.gypi` is used by `node-gyp` to compile addons. Default values
must be provided for variables that may not exist on older versions of
Node.js so that older versions of Node.js can be used to compile addons
for later versions of Node.js.

Add default values for `v8_enable_pointer_compression` and
`v8_enable_31bit_smis_on_64bit_arch`.

PR-URL: #33688
Refs: #30463
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Signed-off-by: Richard Lau <[email protected]>
codebytere pushed a commit that referenced this pull request Jun 30, 2020
`common.gypi` is used by `node-gyp` to compile addons. Default values
must be provided for variables that may not exist on older versions of
Node.js so that older versions of Node.js can be used to compile addons
for later versions of Node.js.

Add default values for `v8_enable_pointer_compression` and
`v8_enable_31bit_smis_on_64bit_arch`.

PR-URL: #33688
Refs: #30463
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Signed-off-by: Richard Lau <[email protected]>
codebytere pushed a commit that referenced this pull request Jul 9, 2020
`common.gypi` is used by `node-gyp` to compile addons. Default values
must be provided for variables that may not exist on older versions of
Node.js so that older versions of Node.js can be used to compile addons
for later versions of Node.js.

Add default values for `v8_enable_pointer_compression` and
`v8_enable_31bit_smis_on_64bit_arch`.

PR-URL: #33688
Refs: #30463
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Signed-off-by: Richard Lau <[email protected]>
@richardlau richardlau mentioned this pull request Jul 14, 2020
@jdmarshall
Copy link

Why wouldn’t this be useful now that we’re on node 18?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. build Issues and PRs related to build files or the CI. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.