Skip to content
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

feat(wasm): use only one Engine per global context #5447

Conversation

ureeves
Copy link

@ureeves ureeves commented Nov 11, 2024

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

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
Copy link

@csgui csgui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM. Just a remark.

Since this PR changes how the context is initialized and likely impacts the roundtrip on contract calls, it would be useful to benchmark and profile the code both before and after this PR.

@obycode What do you think about making an effort to compare the changes and their impact on contract calls introduced by this PR?

@obycode
Copy link
Contributor

obycode commented Nov 12, 2024

I think this is a definite improvement, but does not yet close stacks-network/clarity-wasm#468. For that issue, I'd like to go further and link in the callee contract into the current Wasm instance to call the function directly, rather than leaving Wasm and passing through Rust to go back to Wasm.

@obycode
Copy link
Contributor

obycode commented Nov 12, 2024

I added a diagram in the issue to help clarify.

@obycode obycode merged commit 05467a2 into stacks-network:feat/clarity-wasm-develop Nov 12, 2024
22 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants