Skip to content

Commit

Permalink
Add a Component::initialize_copy_on_write_image function
Browse files Browse the repository at this point in the history
Add a component version of the existing
`Module::initialize_copy_on_write_image` function. For components, this
initializes the copy-on-write images for all contained static modules.
This function is just for optimization purposes, and is not required to
be called.
  • Loading branch information
sunfishcode committed Oct 1, 2024
1 parent c6da7d8 commit ee974c9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions crates/wasmtime/src/runtime/component/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,30 @@ impl Component {
self.inner.code.code_memory().mmap().image_range()
}

/// Force initialization of copy-on-write images to happen here-and-now
/// instead of when they're requested during first instantiation.
///
/// When [copy-on-write memory
/// initialization](crate::Config::memory_init_cow) is enabled then Wasmtime
/// will lazily create the initialization image for a component. This method
/// can be used to explicitly dictate when this initialization happens.
///
/// Note that this largely only matters on Linux when memfd is used.
/// Otherwise the copy-on-write image typically comes from disk and in that
/// situation the creation of the image is trivial as the image is always
/// sourced from disk. On Linux, though, when memfd is used a memfd is
/// created and the initialization image is written to it.
///
/// Also note that this method is not required to be called, it's available
/// as a performance optimization if required but is otherwise handled
/// automatically.
pub fn initialize_copy_on_write_image(&self) -> Result<()> {
for (_, module) in self.inner.static_modules.iter() {
module.initialize_copy_on_write_image()?;
}
Ok(())
}

/// Looks up a specific export of this component by `name` optionally nested
/// within the `instance` provided.
///
Expand Down

0 comments on commit ee974c9

Please sign in to comment.