Skip to content

Conversation

@chirino
Copy link
Collaborator

@chirino chirino commented Jun 13, 2025

…sses

  • Add copy() method to Instance class for creating deep copies of WebAssembly runtime state
  • Implement copy() methods in GlobalInstance, TableInstance, and TagInstance classes
  • Add copy() interface method to Memory with implementations in ByteArrayMemory and ByteBufferMemory
  • Extend ImportValues with copy() method for deep copying import state
  • Create comprehensive InstanceCopyTest with test cases for all copy scenarios
  • Add global-counter.wat test module with compiled WASM binary for testing global state copying
  • Update wasm-corpus Dockerfile to include wabt tools for WebAssembly compilation
  • Add copyWithOptions() method that allows you to change the listen or imports for the new instance copy.

This implementation enables creating independent copies of WebAssembly runtime instances with fully isolated state, including memory contents, global variables, tables, tags, and import values. This is essential for scenarios requiring instance isolation, snapshotting, or parallel execution contexts.

…sses

- Add copy() method to Instance class for creating deep copies of WebAssembly runtime state
- Implement copy() methods in GlobalInstance, TableInstance, and TagInstance classes
- Add copy() interface method to Memory with implementations in ByteArrayMemory and ByteBufferMemory
- Extend ImportValues with copy() method for deep copying import state
- Create comprehensive InstanceCopyTest with test cases for all copy scenarios
- Add global-counter.wat test module with compiled WASM binary for testing global state copying
- Update wasm-corpus Dockerfile to include wabt tools for WebAssembly compilation
- Add copyWithOptions() method that allows you to change the listen or imports for the new instance copy.

This implementation enables creating independent copies of WebAssembly runtime instances with fully isolated state, including memory contents, global variables, tables, tags, and import values.  This is essential for scenarios requiring instance isolation, snapshotting, or parallel execution contexts.

Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
…name it Experimental

And document that it’s dangerous to use.

Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
GlobalInstance copy =
new GlobalInstance(
this.valueLow, this.valueHigh, this.valType, this.mutabilityType);
// The instance field will be set by the calling code
Copy link
Collaborator

Choose a reason for hiding this comment

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

The need of resetting/recomputing fields shows that this is a leaky abstraction.

@andreaTP
Copy link
Collaborator

andreaTP commented Nov 6, 2025

For reference, wasmtime experimented with those things:
https://bytecodealliance.org/articles/wasmtime-10-performance

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.

2 participants