-
Notifications
You must be signed in to change notification settings - Fork 18
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
Improve contract-call?
implementation
#468
Comments
Note: this change might help with issue #409. |
Instantiating a `wasmtime::Engine` is an expensive operation, so it is best to do it only once for the duration of a `GlobalContext`. Cloning an engine is, however, not an expensive operation (just an `Arc::clone`) and we use it to avoid referring to the global context while while instantiating a `ClarityWasmContext`. See-also: stacks-network/clarity-wasm#468
Instantiating a `wasmtime::Engine` is an expensive operation, so it is best to do it only once for the duration of a `GlobalContext`. Cloning an engine is, however, not an expensive operation (just an `Arc::clone`) and we use it to avoid referring to the global context already referred to by the instantiated `ClarityWasmContext`. See-also: stacks-network/clarity-wasm#468
To try to help clarify this, currently we have:
What I think we want is:
|
I've been exploring ways to achieve this, but think it is possible only under certain conditions. As far as I can see there's two distinct cases of relevance. I mostly ignore the function name in my explainers, since it is equivalent to the contract identifier in the scope of the possible changes.
|
Thanks for this writeup! One thing that we know is true is that given the arguments to a contract call, we can know all possible contracts that could be reached through that contract call. Given that, all contracts can be loaded before entering Wasm. I believe it should be possible to implement some sort of dynamic dispatch mechanism within Wasm to call into the correct contracts based on the traits that are passed around. I do not have a full design in mind for this though. It definitely could end up being more complicated than is worth it. I agree completely that we should definitely explore the performance of these options with benchmarks, especially if the linker option proves to be difficult to implement. Please also include in this benchmarking the other improvement that we discussed, of simply avoiding the serialization/deserialization of the values and instead use a direct memory copy from one contract to the other. Basically switching from: Contract A (Wasm) serialize --> Rust read from A and deserialize --> Rust serialize and write to B --> Contract B (Wasm) deserialize to: Rust copy from contract A to contract B |
After some more thinking about this and looking into what wasm and wasmtime are capable of, I agree that our best option is to let the host handle the dynamic dispatch. |
Currently, calling another contract involves spinning up a separate Wasm VM to execute the callee, then return results to the caller, which is quite resource intensive. It would be much better to instead load the callee and link it into the caller's VM.
The text was updated successfully, but these errors were encountered: