-
Notifications
You must be signed in to change notification settings - Fork 343
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
Enable FinalizationRegistry #3560
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1431,7 +1431,7 @@ class ResourceWrapper { | |
// We do not allow use of WeakRef or FinalizationRegistry because they introduce | ||
// non-deterministic behavior. | ||
check(global->Delete(context, v8StrIntern(isolate, "WeakRef"_kj))); | ||
check(global->Delete(context, v8StrIntern(isolate, "FinalizationRegistry"_kj))); | ||
//check(global->Delete(context, v8StrIntern(isolate, "FinalizationRegistry"_kj))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably needs a compat flag as I suspect there are people that check for the existence of these APIs and use them if they are available -- making them suddenly available would therefore cause such workers to start taking a new code path which could end up being broken. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that was something on my mind as well, had a brief discussion with @mikenomitch about placing this behind a compat date/flag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes me sad, but yes, compat flag absolutely needed. I've seen such checks in the wild a few times now. |
||
|
||
// Store a pointer to this object in slot 1, to be extracted in callbacks. | ||
context->SetAlignedPointerInEmbedderData(1, ptr.get()); | ||
|
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.
We'd be enabling
WeakRef
too right?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 current plan is to only enable
FinalizationRegistry
, given the immediate memory cleanup benefits for wasm users.WeakRef
is something we can probably think about as a followup.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.
Is there actually anything more needed to enable WeakRef? If it's just a matter of removing the line above, I think we should do it in this change.
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.
Yes it should work by just removing the line, although @harrishancock was concerned about
WeakRef
giving immediate notification of GC collection instead ofFinalizationRegistry
which is more non-deterministic.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.
WeakRef
does not give immediate notification thankfully. I suppose someone could poll it as quickly as possible to approximate immediate notification but thankfully it does not provide a notification api.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.
My concern isn't immediate notification, but lack of control over when notifications occur. With FinalizationRegistry, we can control exactly when finalization callbacks are scheduled. With WeakRef, we have no control over when they appear empty -- that's entirely up to the GC. So, if controlling the timing of GC observation is important for risk mitigation, then enabling WeakRef is strictly higher risk than enabling FinalizationRegistry.
That said, I'd love to just accept the risk and enable WeakRef and be done with it.
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'm good with accepting the risk as I thinks it is likely quite minimal. @kentonv ?