Add MemorySize API to expose WASM linear memory size#1
Merged
Conversation
Add MemorySizer interface to wasmruntime, Size() to WazeroMemory, MemorySize() to WazeroInstance and runtime.Instance. Returns current linear memory size in bytes, or 0 when no memory is present.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new interface for querying the size of WASM linear memory and implements it throughout the engine and runtime layers. It also adds comprehensive tests to ensure correct behavior for memory sizing. The changes improve introspection capabilities for WASM instances and memory, making it easier to verify and debug memory allocation and usage.
New memory sizing interface and implementation:
MemorySizerinterface with aSize()method towasm.go, and implemented it forWazeroMemory. This allows querying the current linear memory size in bytes. [1] [2]MemorySize()method for bothWazeroInstanceand high-levelInstance, enabling users to easily retrieve memory size from WASM instances. [1] [2]Testing enhancements:
WazeroInstance.MemorySize()andWazeroMemory.Size()inengine/wazero_test.go, covering scenarios with different memory page sizes and nil memory.Instance.MemorySize()inruntime/runtime_test.go, validating memory size for a loaded WASM component and ensuring it is a non-zero multiple of the page size.