Liveslots should avoid probing WeakRef through deref to check target state #6801
Labels
enhancement
New feature or request
liveslots
requires vat-upgrade to deploy changes
SwingSet
package: SwingSet
What is the Problem Being Solved?
Liveslots probes the state of a target using
weakRef.deref()
, without using the target. This is an anti-pattern in JS as it prevent gc of the target for an implementation defined amount of time. Instead it should solely rely onFinalizationRegistry
callbacks to inform its accounting.When a WeakRef is
deref
ed, the target (if not collected) will be added to a host kept object list. Per spec that list cannot be cleared during the current synchronous execution (turn). However it's not guaranteed the list will be cleared at the end of the current turn, and indeed XS currently has a sub-optimal implementation that only clears the list after draining the promise queue.This has 2 impact in our case:
This xsnap behavior probably explain workarounds like:
agoric-sdk/packages/SwingSet/src/lib-nodejs/gc-and-finalize.js
Lines 83 to 84 in 72d576e
That said, even if the xsnap behavior was changed to clear kept objects more aggressively after each synchronous execution, there is still no reason to for liveslots to probe a weakref if it doesn't intend to use and pass the target to guest code. It prevents collection at best in the current turn where liveslots performed this probing.
I have raised this issue before, e.g. in #3732 (comment)
Description of the Design
If liveslots doesn't need the target of a weakref (the program isn't trying to get a virtual object representative, or we're not passing a presence in a delivery), then liveslots should rely on its existing understanding of the target's state as tracked by its FinalizationRegistry callbacks.
The text was updated successfully, but these errors were encountered: