- Can talk to the DOM directly
- Is always the first thing that is executed in browsers
- Can do multiple threads vs web work workers
- Very slow at math
- Has very little control over memory management
- Supports a variety of languages
- Extremely fast
- Full control over memory
- single process
- no access to environment
Pretty much the only game in town right now for writing web experiences using WebAssembly requires holding onto handles to the host environment’s resources (i.e. an integer that represents a DOM element in a dictionary somewhere).
- Whenever web assembly needs to operate on that host environment resource, call an external function with that handle
4. External function implementation looks up resource with handle
It seems like a simple plan until you have to ask the question “how long should I store a mapping of a handle to an host resource?”
Right now Web Assembly in the browser is very restrained in its knowledge about things in the host environment, to know something is alive, it must keep a memory reference to it, but by keeping a memory reference to it, it will keep it alive.
In a perfect world, we have a very clear and direct lifetime on how long resources should be held for, but lets face it, in an async and multi threaded world, it’s easy to lose track of who is messing with what.
Rather than having strong handles to resources outside of your web assembly module, wouldn’t it be nice to point to things in the host environment and not have to worry about memory leaks if that resource gets trashed by some other operation?
I’m looking forward to seeing how web assembly frameworks evolve in a world where it can hold onto things loosely. If you have interest in seeing this evolve, be on the lookout for