wasmtime: Option to disable parallel compilation (#3169)

* Introduce parallel-compilation configuration switch

* Plumb parallel_compilation config to compilation

* Adjust obj.rs

* Address review

* Fix compilation fail in `cache` crate

* Fix obj.rs

Also remove the now unneeded feature in /Cargo.toml

* fmt
This commit is contained in:
Sergei Shulepov
2021-08-10 21:09:15 +02:00
committed by GitHub
parent 42acb72c54
commit cbabcacb0f
8 changed files with 81 additions and 30 deletions

View File

@@ -356,6 +356,7 @@ pub struct Config {
pub(crate) async_stack_size: usize,
pub(crate) async_support: bool,
pub(crate) deserialize_check_wasmtime_version: bool,
pub(crate) parallel_compilation: bool,
}
impl Config {
@@ -392,6 +393,7 @@ impl Config {
async_stack_size: 2 << 20,
async_support: false,
deserialize_check_wasmtime_version: true,
parallel_compilation: true,
};
ret.cranelift_debug_verifier(false);
ret.cranelift_opt_level(OptLevel::Speed);
@@ -1210,6 +1212,18 @@ impl Config {
self
}
/// Configure wether wasmtime should compile a module using multiple threads.
///
/// Disabling this will result in a single thread being used to compile the wasm bytecode.
///
/// By default parallel compilation is enabled.
#[cfg(feature = "parallel-compilation")]
#[cfg_attr(nightlydoc, doc(cfg(feature = "parallel-compilation")))]
pub fn parallel_compilation(&mut self, parallel: bool) -> &mut Self {
self.parallel_compilation = parallel;
self
}
pub(crate) fn target_isa(&self) -> Box<dyn TargetIsa> {
self.isa_flags
.clone()
@@ -1226,7 +1240,13 @@ impl Config {
let isa = self.target_isa();
let mut tunables = self.tunables.clone();
allocator.adjust_tunables(&mut tunables);
Compiler::new(isa, self.strategy, tunables, self.features)
Compiler::new(
isa,
self.strategy,
tunables,
self.features,
self.parallel_compilation,
)
}
pub(crate) fn build_allocator(&self) -> Result<Box<dyn InstanceAllocator>> {

View File

@@ -300,11 +300,19 @@ impl Module {
engine.cache_config(),
)
.get_data((engine.compiler(), binary), |(compiler, binary)| {
CompilationArtifacts::build(compiler, binary, USE_PAGED_MEM_INIT)
CompilationArtifacts::build(
compiler,
binary,
USE_PAGED_MEM_INIT,
)
})?;
} else {
let (main_module, artifacts, types) =
CompilationArtifacts::build(engine.compiler(), binary, USE_PAGED_MEM_INIT)?;
CompilationArtifacts::build(
engine.compiler(),
binary,
USE_PAGED_MEM_INIT,
)?;
}
};
@@ -312,6 +320,7 @@ impl Module {
artifacts,
engine.compiler().isa(),
&*engine.config().profiler,
engine.compiler(),
)?;
Self::from_parts(engine, modules, main_module, Arc::new(types), &[])

View File

@@ -291,6 +291,7 @@ impl<'a> SerializedModule<'a> {
.collect(),
engine.compiler().isa(),
&*engine.config().profiler,
engine.compiler(),
)?;
assert!(!modules.is_empty());