When working on JAWSM one thing that is fairly limiting is not being able to use a WeakMap or a similar structure based on weak references. The most notable example is String interner. In JS implementations one typically uses integer values to access properties and variables. When the code is parsed all of the identifiers and literals are interned and given an integer value, but the same thing has to happen for all of the dynamic values. For example, consider the following code:
let obj = {};
obj[Math.random(10)] = "foo";
it's best to do the property lookup by an i32 value cause of performance and simplicity, but we can't intern the String at compile time as it will be known only after executing the code. As far as I know, the simple implementation in JS engines is to have a global interner built using some kind of WeakMap like structure (I'm sure V8 and other advanced engines do much more than that, though).
Because of the lack of WeakMap in WebAssembly I'm doing something way less performant. Each object that can have dynamic properties has its own internal interner that maps strings to integers. The situation is the same for Symbols. I think other lang implementations based on GC would face similar problems.
I couldn't find any information about a plan to introduce weak references to WebAssembly. Is that information correct? Are there any efforts to do that?
I did find some mentions of weak references here, though it's been a while:
https://github.com/WebAssembly/component-model/issues/278#issuecomment-1839546259
Weak references and finalizers are listed as an Post MVP item in GC proposal, but I don't know if anybody stared working on this or have concrete plans:
https://github.com/WebAssembly/gc/blob/main/proposals/gc/Post-MVP.md#weak-references
Last updated: Jan 24 2025 at 00:11 UTC