-
Notifications
You must be signed in to change notification settings - Fork 217
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
fix(swingset,xsnap): add gcAndFinalize, tests #3136
Conversation
b5dc16c
to
feca9cf
Compare
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.
The code looks good.
Since changelogs for SwingSet and xsnap are built from conventional commits, I suggest (but don't require) two commits:
- The xsnap.c change would go in:
- fix: let finalizers run after empty promise queue, before timer events - The rest would go in:
- feat: gcAndFinalize: garbage collect and wait for FinalizationRegistry callbacks
The xsnap.c change might even be a feature, depending on which way you want to look at it.
The xsnap.c change would ideally come with a test in that package since, for example, the whole package is likely to move to endojs, where someone might look at it and wonder "why is this extra loop in here?"
1e750e1
to
9b6fbbe
Compare
Done.. please take another look and see if I missed anything. |
Looks good. The test in xsnap looks a little verbose, but seems ok. |
9b6fbbe
to
300afe0
Compare
300afe0
to
6a260e3
Compare
This changes the xsnap.c run loop to give finalizers a chance to run just after the promise queue drains. With this change, userspace can do a combination of `gc()` and `setImmediate` that lets it provoke a full GC sweep, and wait until finalizers have run. SwingSet will use this during a crank, after userspace has become idle, and before end-of-crank GC processing takes place. This combination is implemented in a function named `gcAndFinalize()`. We copy this function from its normal home in SwingSet so the xsnap.c behavior it depends upon can be tested locally. refs #2660
This adds a platform-specific `gcAndFinalize()` function, which returns a Promise that resolves when GC has been provoked and FinalizationRegistry callbacks have had a chance to run. On Node.js, the application must be run with --expose-gc . refs #2660
6a260e3
to
d4bc617
Compare
I added this to SwingSet/package.json in commit d4bc617 (PR #3136). However I overlooked the fact that #3100 had already landed, which changed the top-level `yarn test` from one that just did a (sequential) `yarn workspaces test`, testing one package at a time with whatever the local `package.json` said to do, to one that does a (parallel) `ava` invocation, which does all packages at the same time but ignores the local `package.json` settings. We need to include `--expose-gc` in the `nodeArguments` in the top-level package.json to make sure the parallel form give the correct arguments when SwingSet's turn comes around (as well as other packages which benefit from enabling GC but don't have tests which directly assert that it can be done).
I added this to SwingSet/package.json in commit d4bc617 (PR #3136). However I overlooked the fact that #3100 had already landed, which changed the top-level `yarn test` from one that just did a (sequential) `yarn workspaces test`, testing one package at a time with whatever the local `package.json` said to do, to one that does a (parallel) `ava` invocation, which does all packages at the same time but ignores the local `package.json` settings. We need to include `--expose-gc` in the `nodeArguments` in the top-level package.json to make sure the parallel form give the correct arguments when SwingSet's turn comes around (as well as other packages which benefit from enabling GC but don't have tests which directly assert that it can be done).
This adds a platform-specific
gcAndFinalize()
function, which returns aPromise that resolves when GC has been provoked and FinalizationRegistry
callbacks have had a chance to run.
On Node.js, the application must be run with --expose-gc . On
xsnap
, asmall change was made to the run loop to let finalizers run before after the
promise queue is empty and before timer events run.
refs #2660