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

doc: modified docs to reflect how to invoke gc on Wrapping C++ objects #20431

Closed
wants to merge 4 commits into from
Closed

doc: modified docs to reflect how to invoke gc on Wrapping C++ objects #20431

wants to merge 4 commits into from

Conversation

isurusiri
Copy link
Contributor

Currently the documentation for Wrapping C++ Objects doesn't explain
how to destruct an object by explicitly invoking the garbage collector.
This commit includes a modification to docs that explains how to force
the garbage collector to clear objects using V8's command line flags.

Fixes: #19876

Checklist

Currently the documentation for Wrapping C++ Objects doesn't explain
how to destruct an object by explicitly invoking the garbage collector.
This commit includes a modification to docs that explains how to force
the garbage collector to clear objects using V8's command line flags.

Fixes: #19876
Currently the documentation for Wrapping C++ Objects doesn't explain
how to destruct an object by explicitly invoking the garbage collector.
This commit includes a modification to docs that explains how to force
the garbage collector to clear objects using V8's command line flags.

Fixes: #19876
@nodejs-github-bot nodejs-github-bot added addons Issues and PRs related to native addons. doc Issues and PRs related to the documentations. labels Apr 30, 2018
@vsemozhetbyt
Copy link
Contributor

@Trott
Copy link
Member

Trott commented May 1, 2018

@nodejs/addon-api Is this information we'd want to include?

Since these are V8 internal flags, @nodejs/v8 also might have opinions on whether we should include this information in our docs or not.

If we do want to include it, the text could benefit from a bit of editing. Maybe @nodejs/documentation can offer some suggested alternative wording etc.

@Trott
Copy link
Member

Trott commented May 1, 2018

Prior conversation for context: #20269

@hashseed
Copy link
Member

hashseed commented May 1, 2018

Personally I don't think using --gc-global and --gc-interval is any better than triggering gc directly via gc(). None of these are public APIs. Though people are probably more likely to avoid --gc-inteval since it seriously degrades performance.

Can't we write these demo cases or tests in a way that at the end it keeps allocating until the destroy callback fires? Failing tests become timeouts, which is not ideal, but aside from that this is nicer than recommending V8's debugging flags.

@isurusiri
Copy link
Contributor Author

Conclusion of previous discussions (#20269 (comment)) is that we shouldn't document something like allocating a large number of objects to trigger GC mainly because it is going to official docs and coding a bad practice that could be misleading. Therefore we could document v8 flags highlighting those are only for testing purposes and provided by V8 would be enough.

` --gc_interval ` forces V8 to perform garbage collection after a given amount
of allocations. Although, it is recommended to limit V8 command line flags
for testing purposes only, since these are primarily debug flags.

Copy link
Member

@Trott Trott May 2, 2018

Choose a reason for hiding this comment

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

How about this?:

The destructor for a wrapper object will run when the object is
garbage-collected. For destructor testing, there are command-line flags that can
be used to make it possible to force garbage collection. These flags are
provided by the underlying V8 JavaScript engine. They are subject to change or
removal at any time. They are not documented by Node.js or V8, and they should
never be used outside of testing.

Or if that's too mysterious, maybe this?:

The destructor for a wrapper object will run when the object is
garbage-collected.

Leave it as an exercise for the reader to figure out how to force garbage collection for testing purposes. People can find that in blog posts and StackOverflow etc. (For example, https://stackoverflow.com/q/27321997/436641.) But we don't have to document it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree with leaving reader to figure it out since we are not recommending to use command line flags outside of testing. First options is informative and I'll proceed with that.

Currently the documentation for Wrapping C++ Objects doesn't explain
how the destructor executes when garbage-collector runs. This commit
includes a modification to docs that instructs how the destructor
for wrapper objects will run and options available to test destructor

Fixes: http://github.com/nodejs/node/issues/19876
@Trott
Copy link
Member

Trott commented May 3, 2018

@bnoordhuis @hashseed PTAL

@addaleax
Copy link
Member

addaleax commented May 6, 2018

@hashseed I think for --expose-gc not having to be considered public API the ship has sailed a long time ago. Not saying that’s a good thing – I just think it’s something we’re locked into. A lot of test suites for Node addons use it in the way described here, to the degree that some test runners/frameworks have explicit builtin support for making tests run with this flag (e.g. mocha).

Regarding this PR, I like the idea but it’s probably not very meaningful to say “There are undocumented flags that do exactly what you need right now, please don’t look them up because that’s a bad thing”. I’d be okay with officially recommending --expose-gc, but don’t really want to do that over the V8 team’s head either.

@BridgeAR
Copy link
Member

@hashseed I think @addaleax has a good point here. That flag is indeed pretty commonly used.

@jasnell
Copy link
Member

jasnell commented Sep 10, 2018

Ping... what's the status on this one?

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Sep 10, 2018
@addaleax
Copy link
Member

It might be good to hear what @hashseed thinks of the above – again, I’m really not saying I’m a fan of us effectively making a V8 flag public API, but we have to face the fact that it effectively is.

The destructor for a wrapper object will run when the object is
garbage-collected. For destructor testing, there are command-line flags that
can be used to make it possible to force garbage collection. These flags are
provided by the underlying V8 JavaScript engine. They are subjected to change
Copy link
Member

Choose a reason for hiding this comment

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

Nit: subjected -> subject

@hashseed
Copy link
Member

I'm happy with the current wording.

@Trott
Copy link
Member

Trott commented Sep 17, 2018

@Trott Trott added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 17, 2018
@addaleax
Copy link
Member

@Trott
Copy link
Member

Trott commented Sep 18, 2018

@Trott
Copy link
Member

Trott commented Sep 18, 2018

Hmmm, the same unrelated TLS test failing three times. Let's try a fresh run rather than a Replay and see if that clears up some git stuff leftover from another run or something weird like that which might be causing it. Yeah, I'm making it up. Let's try it anyway: https://ci.nodejs.org/job/node-test-pull-request-lite-pipeline/920/

@Trott
Copy link
Member

Trott commented Sep 18, 2018

That time, it was a hard build failure. I've pinged build folks to take a look and hopefully it will be fixed soon and we can try again. Sorry about the delay.

@Trott
Copy link
Member

Trott commented Sep 18, 2018

Looks like I kicked off the job incorrectly. Let's try again: https://ci.nodejs.org/job/node-test-pull-request-lite-pipeline/926/

@Trott
Copy link
Member

Trott commented Sep 18, 2018

Giving up on lite CI, going for full CI: https://ci.nodejs.org/job/node-test-pull-request/17299/

@Trott
Copy link
Member

Trott commented Sep 19, 2018

Trott pushed a commit to Trott/io.js that referenced this pull request Sep 19, 2018
Currently the documentation for Wrapping C++ Objects doesn't explain
how to destruct an object by explicitly invoking the garbage collector.
This commit includes a modification to docs that explains how to force
the garbage collector to clear objects using V8's command line flags.

Fixes: nodejs#19876

PR-URL: nodejs#20431
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yang Guo <yangguo@chromium.org>
@Trott
Copy link
Member

Trott commented Sep 19, 2018

Finally...

Landed in a1381fa

@Trott Trott closed this Sep 19, 2018
targos pushed a commit that referenced this pull request Sep 19, 2018
Currently the documentation for Wrapping C++ Objects doesn't explain
how to destruct an object by explicitly invoking the garbage collector.
This commit includes a modification to docs that explains how to force
the garbage collector to clear objects using V8's command line flags.

Fixes: #19876

PR-URL: #20431
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yang Guo <yangguo@chromium.org>
targos pushed a commit that referenced this pull request Sep 20, 2018
Currently the documentation for Wrapping C++ Objects doesn't explain
how to destruct an object by explicitly invoking the garbage collector.
This commit includes a modification to docs that explains how to force
the garbage collector to clear objects using V8's command line flags.

Fixes: #19876

PR-URL: #20431
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yang Guo <yangguo@chromium.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addons Issues and PRs related to native addons. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. doc Issues and PRs related to the documentations. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants