Skip to content

feat: add ability to configure static memory size#763

Closed
zshipko wants to merge 3 commits intomainfrom
dynamic-memory
Closed

feat: add ability to configure static memory size#763
zshipko wants to merge 3 commits intomainfrom
dynamic-memory

Conversation

@zshipko
Copy link
Copy Markdown
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
Copy Markdown
Member

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

@zshipko
Copy link
Copy Markdown
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


/// 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
Copy Markdown
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
Copy Markdown
Contributor Author

zshipko commented Sep 18, 2024

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

zshipko pushed 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
Copy Markdown
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