Skip to content

Conversation

zshipko
Copy link
Contributor

@zshipko zshipko commented Sep 17, 2024

This makes it possible to configure the amount of memory that's allocated up front when instantiating a plugin.

Also adds a default static memory size of 4GB to the C API.

@nilslice
Copy link
Member

Nice! What happens if this limit is exceeded? And is it only upon instantiation?

@zshipko
Copy link
Contributor Author

zshipko commented Sep 17, 2024

If the limit is exceeded then it switches to dynamic memory, where more memory is allocated and the old memory is copied over - so there is some performance downside to growing memory at that point. More information here: https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.static_memory_maximum_size

pub fn with_fuel_limit(mut self, fuel: u64) -> Self {
self.fuel = Some(fuel);
self
}

/// Limit the size of the memory allocated up-front when
/// instantiating a module
pub fn with_static_memory_size(mut self, size: u64) -> Self {
Copy link
Contributor

@SebastianHambura SebastianHambura Sep 18, 2024

Choose a reason for hiding this comment

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

Considering the potential performance implications, and the big warnings from the underlaying wasmtime function's documentation, maybe it would be worth it to add a link to https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.static_memory_maximum_size in this function's documentation.
Just so people not aware don't accidently change that setting without understanding

@zshipko
Copy link
Contributor Author

zshipko commented Sep 18, 2024

I just opened #764, which solves the same problem in a more general way

zshipko added a commit that referenced this pull request Sep 19, 2024
An alternative to #763, this PR allows an initial `wasmtime::Config` to
be passed in when building a plugin. Some of these values may be
overwritten by the Extism runtime, but it allows for things like static
memory size and other low-level details to be handled directly instead
of us having to wrap every option ourselves.
@zshipko
Copy link
Contributor Author

zshipko commented Sep 19, 2024

Closing this after merging #764

@zshipko zshipko closed this Sep 19, 2024
@zshipko zshipko deleted the dynamic-memory branch September 20, 2024 17:14
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.

3 participants