Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wasmtime precompilation #700

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion crates/containerd-shim-wasmtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,17 @@ impl<T: WasiConfig> Engine for WasmtimeEngine<T> {
continue;
}

let compiled_layer = self.engine.precompile_module(&layer.layer)?;
use WasmBinaryType::*;

let compiled_layer = match WasmBinaryType::from_bytes(&layer.layer) {
Some(Module) => self.engine.precompile_module(&layer.layer)?,
Some(Component) => self.engine.precompile_component(&layer.layer)?,
None => {
log::warn!("Unknow WASM binary type");
continue;
}
};

Comment on lines +122 to +130
Copy link
Member

Choose a reason for hiding this comment

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

suggest: move this logic to Engine and add a method called fn precompile(). It is the job of the engine to handle the type of compiled_layer

Copy link
Collaborator

Choose a reason for hiding this comment

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

So instead of Engine::precompile like we have now, it would be Engine::precompile_module and Engine::precompile_component?
Sounds god to me.
Alternatively, a layer could have a is_component(&self) -> bool method, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is the job of the engine to handle the type of compiled_layer

Not sure I understand this statement. note we have this type of logix else where in this shim https://github.com/andreiltd/runwasi/blob/e07255e7d1b6ea07ff3daa783782defd317d18b5/crates/containerd-shim-wasmtime/src/instance.rs#L258-L259

it would be Engine::precompile_module and Engine::precompile_component?
I am not excited about chaning the api or making the engine have to iterate through the layers. We delegate that to the instance so shims can handle there own layer types.

Alternatively, a layer could have a is_component(&self) -> bool method, WDYT?

Something like this makes sense if we want to move the logic our of here. Maybe a enum instead of a bool though? In spin shim it currently supports of ther layer types. We don't really wanto

compiled_layers.push(Some(compiled_layer));
}

Expand Down
Loading