I am trying to help as I can to ship the next Python / JS FFI proposal and itās clear, not only for Python but for the entirety of PLs running in WASM, there is a need to make some observed/registered reference greedier than others, yet the FinalizationRegistry API does not allow anything like a priority task, which default would be āwhateverā (metaphorically speaking) but that could instead be foreign or high-priority or greedy or ⦠you name it (I wouldnāt mind the name resolution, itās the concept I am after).
Background
WASM targeting runtimes and PLs are based on SharedArrayBuffer which is something that can only grow over time and never shrink ⦠when interoperability or any FFI attempt is present to deal with the outer JS world, there is a topic not many are discussing or are even aware of: concurrent GC pressure.
While on the JS side of affairs the engine can decide when itās about the time to run any GC related issue because maybe the used RAM is too high, the counter-part PL on the WASM side of affairs is screaming for collection of those references passed along, preserved as identity, and incapable of freeing themselves unless risky proxy.destroy() operations happen, due memory limits constrainta, leaving dangling and dead proxy pointers on the JS side.
This situation has forced projects like Pyodide to be paranoid about it, but pretty much every other PL targeting WASM has the same issue: Lua, Ruby, PHP, even QuickJS, running as JS alter-ego has issues with the fact JS canāt be forced to GC but it can inevitably make these runtimes fail on claiming more RAM, slowing these down when re-allocating memory is needed, and being incapable to keep the amount of needed SharedArrayBuffer reasonable.
Proposal
Unfortunately the [FinalizationRegistry register]( ECMAScriptĀ® 2026 Language Specification ) method was layed out with an unfortunate extra 3rd argument that would be the eventual token to unregister any reference, so here I am asking for an optional 4th argument that optionally dictates the desire to track that more greedly than others, as in the string `short` to indicate the hopeful lifetime of that registered reference, or a new method all together, because the third argument cannot be an object or a reference, as thatās specād already as token reference to unregister the first argument.
Honestly, any idea that could help pursue the goal would be more than welcomed, but itās super clear while PLs on their side can hook into what should be collected or not (in this case CPython) we have nothing like āshould be freed ASAPā on the JS side, still not observable, yet great as a hint for interoperability purposes ⦠the currently proposed *FFI* solution is otherwise cumbersome, awkward, usersā not friendly at all, and so on ⦠thanks!