-
-
Notifications
You must be signed in to change notification settings - Fork 670
Sharing Linear Memory/Runtime Between Modules #887
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
Comments
That's an interesting approach. As you noted, there'll most likely be more to it, but I like the idea of making the RT a shared module. Goes into the direction of dynamic linking, though, which there isn't a good story for in Wasm yet without multiple memories. Wondering whether something like a Laying out memory regions for all modules in advance would also work, but I assume that'd be a somewhat painful process. Essentially, the first module would do things normally, with the second using the final value of A third approach might be to extend the compiler with a mechanism to emit fully relocatable modules, with each load and store being offset by an imported A more general issue I see is that the modules wouldn't share stdlib, so if something of stdlib utilizes a global, that won't be synced between all the modules. Might or might not be a problem, but not sharing stdlib definitely leads to redundant code, like each module having its own implementation of |
Thanks for your insight @dcodeIO I'll work through your ideas and see what I can come up with. The other patterns we have narrowed down
But i kind of prefer this shared runtime pattern if we can work through the details, it fits our plugin system rather nicely. I'll close this out as you answered my questions, and you can reopen if you would like to keep it active. |
So I've toyed around with relocation support a bit, and figured that a relatively straight-forward solution might be to
While such a module can be emitted (offsets are just expressions), Binaryen and Wasm engines do not permit computed offsets on |
Does anyone happen to know whether relocation sections are a thing already? |
It seems that it depends on the tool you are using. From the readme:
I think some form of WASM linking is supported in |
While evaluating AS as the basis for our new plugin system for indis.io we had been playing around with passing AS types (i.e. string/array/classes/etc) between multiple instances, similar to the question in #606.
To be clear they goal for us differs from some of the other PRs like #278 as we aren't targeting multi-threaded at the moment, we are just trying to make it easier for plugin authors to not have to deal with the idiosyncrasies of wasm.
i have created a fork/branch with one of the implementations we have been looking at. https://github.com/sampaioletti/assemblyscript/tree/shared-rt/examples/shared-rt
In this sample we are generating a blank module with the run time, and exporting it and the rt methods to two other 'plugins' so they can share the allocater/linear mem. Leaving the plugins very lean since the rely on the imported runtime.
It works as expected with the exception of what happens to wasm data sections (memory initializes) as they will overwrite each other as they are imported.
I'm sure some other issues will show up if this is taken further, but the I'm posting it here as its no where near PR ready and was hoping for some feedback before I dig deeper.
Past this we have looked at some other options but this was our favorite for a first try
Thanks, great project!
The text was updated successfully, but these errors were encountered: