mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 14:41:11 +00:00
Switch to pooling copy-on-write instantiation strategy for WASM (#11232)
* Switch to pooling copy-on-write instantiation strategy for WASM * Fix benchmark compilation * Fix `cargo fmt` * Fix compilation of another benchmark I've missed * Cleanups according to review comments * Move `max_memory_size` to `Semantics` * Set `memory_guaranteed_dense_image_size` to `max_memory_size` * Rename `wasm_instantiation_strategy` to `wasmtime_instantiation_strategy` * Update the doc-comments regarding the instantiation strategy * Extend the integration tests to test every instantiation strategy * Don't drop the temporary directory until the runtime is dropped in benchmarks * Don't drop the temporary directory until the runtime is dropped in tests
This commit is contained in:
@@ -20,6 +20,36 @@
|
||||
|
||||
use clap::ArgEnum;
|
||||
|
||||
/// The instantiation strategy to use in compiled mode.
|
||||
#[derive(Debug, Clone, Copy, ArgEnum)]
|
||||
#[clap(rename_all = "kebab-case")]
|
||||
pub enum WasmtimeInstantiationStrategy {
|
||||
/// Pool the instances to avoid initializing everything from scratch
|
||||
/// on each instantiation. Use copy-on-write memory when possible.
|
||||
PoolingCopyOnWrite,
|
||||
|
||||
/// Recreate the instance from scratch on every instantiation.
|
||||
/// Use copy-on-write memory when possible.
|
||||
RecreateInstanceCopyOnWrite,
|
||||
|
||||
/// Pool the instances to avoid initializing everything from scratch
|
||||
/// on each instantiation.
|
||||
Pooling,
|
||||
|
||||
/// Recreate the instance from scratch on every instantiation. Very slow.
|
||||
RecreateInstance,
|
||||
|
||||
/// Legacy instance reuse mechanism. DEPRECATED. Will be removed in the future.
|
||||
///
|
||||
/// Should only be used in case of encountering any issues with the new default
|
||||
/// instantiation strategy.
|
||||
LegacyInstanceReuse,
|
||||
}
|
||||
|
||||
/// The default [`WasmtimeInstantiationStrategy`].
|
||||
pub const DEFAULT_WASMTIME_INSTANTIATION_STRATEGY: WasmtimeInstantiationStrategy =
|
||||
WasmtimeInstantiationStrategy::PoolingCopyOnWrite;
|
||||
|
||||
/// How to execute Wasm runtime code.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum WasmExecutionMethod {
|
||||
@@ -71,18 +101,33 @@ impl WasmExecutionMethod {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<sc_service::config::WasmExecutionMethod> for WasmExecutionMethod {
|
||||
fn into(self) -> sc_service::config::WasmExecutionMethod {
|
||||
match self {
|
||||
WasmExecutionMethod::Interpreted =>
|
||||
sc_service::config::WasmExecutionMethod::Interpreted,
|
||||
#[cfg(feature = "wasmtime")]
|
||||
WasmExecutionMethod::Compiled => sc_service::config::WasmExecutionMethod::Compiled,
|
||||
#[cfg(not(feature = "wasmtime"))]
|
||||
WasmExecutionMethod::Compiled => panic!(
|
||||
"Substrate must be compiled with \"wasmtime\" feature for compiled Wasm execution"
|
||||
),
|
||||
}
|
||||
/// Converts the execution method and instantiation strategy command line arguments
|
||||
/// into an execution method which can be used internally.
|
||||
pub fn execution_method_from_cli(
|
||||
execution_method: WasmExecutionMethod,
|
||||
_instantiation_strategy: WasmtimeInstantiationStrategy,
|
||||
) -> sc_service::config::WasmExecutionMethod {
|
||||
match execution_method {
|
||||
WasmExecutionMethod::Interpreted => sc_service::config::WasmExecutionMethod::Interpreted,
|
||||
#[cfg(feature = "wasmtime")]
|
||||
WasmExecutionMethod::Compiled => sc_service::config::WasmExecutionMethod::Compiled {
|
||||
instantiation_strategy: match _instantiation_strategy {
|
||||
WasmtimeInstantiationStrategy::PoolingCopyOnWrite =>
|
||||
sc_service::config::WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
|
||||
WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite =>
|
||||
sc_service::config::WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite,
|
||||
WasmtimeInstantiationStrategy::Pooling =>
|
||||
sc_service::config::WasmtimeInstantiationStrategy::Pooling,
|
||||
WasmtimeInstantiationStrategy::RecreateInstance =>
|
||||
sc_service::config::WasmtimeInstantiationStrategy::RecreateInstance,
|
||||
WasmtimeInstantiationStrategy::LegacyInstanceReuse =>
|
||||
sc_service::config::WasmtimeInstantiationStrategy::LegacyInstanceReuse,
|
||||
},
|
||||
},
|
||||
#[cfg(not(feature = "wasmtime"))]
|
||||
WasmExecutionMethod::Compiled => panic!(
|
||||
"Substrate must be compiled with \"wasmtime\" feature for compiled Wasm execution"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,11 @@
|
||||
|
||||
use crate::{
|
||||
arg_enums::{
|
||||
ExecutionStrategy, WasmExecutionMethod, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION,
|
||||
DEFAULT_EXECUTION_IMPORT_BLOCK, DEFAULT_EXECUTION_IMPORT_BLOCK_VALIDATOR,
|
||||
DEFAULT_EXECUTION_OFFCHAIN_WORKER, DEFAULT_EXECUTION_OTHER, DEFAULT_EXECUTION_SYNCING,
|
||||
DEFAULT_WASM_EXECUTION_METHOD,
|
||||
ExecutionStrategy, WasmExecutionMethod, WasmtimeInstantiationStrategy,
|
||||
DEFAULT_EXECUTION_BLOCK_CONSTRUCTION, DEFAULT_EXECUTION_IMPORT_BLOCK,
|
||||
DEFAULT_EXECUTION_IMPORT_BLOCK_VALIDATOR, DEFAULT_EXECUTION_OFFCHAIN_WORKER,
|
||||
DEFAULT_EXECUTION_OTHER, DEFAULT_EXECUTION_SYNCING,
|
||||
DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, DEFAULT_WASM_EXECUTION_METHOD,
|
||||
},
|
||||
params::{DatabaseParams, PruningParams},
|
||||
};
|
||||
@@ -62,6 +63,27 @@ pub struct ImportParams {
|
||||
)]
|
||||
pub wasm_method: WasmExecutionMethod,
|
||||
|
||||
/// The WASM instantiation method to use.
|
||||
///
|
||||
/// Only has an effect when `wasm-execution` is set to `compiled`.
|
||||
///
|
||||
/// The copy-on-write strategies are only supported on Linux.
|
||||
/// If the copy-on-write variant of a strategy is unsupported
|
||||
/// the executor will fall back to the non-CoW equivalent.
|
||||
///
|
||||
/// The fastest (and the default) strategy available is `pooling-copy-on-write`.
|
||||
///
|
||||
/// The `legacy-instance-reuse` strategy is deprecated and will
|
||||
/// be removed in the future. It should only be used in case of
|
||||
/// issues with the default instantiation strategy.
|
||||
#[clap(
|
||||
long,
|
||||
value_name = "STRATEGY",
|
||||
default_value_t = DEFAULT_WASMTIME_INSTANTIATION_STRATEGY,
|
||||
arg_enum,
|
||||
)]
|
||||
pub wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy,
|
||||
|
||||
/// Specify the path where local WASM runtimes are stored.
|
||||
///
|
||||
/// These runtimes will override on-chain runtimes when the version matches.
|
||||
@@ -85,7 +107,7 @@ impl ImportParams {
|
||||
|
||||
/// Get the WASM execution method from the parameters
|
||||
pub fn wasm_method(&self) -> sc_service::config::WasmExecutionMethod {
|
||||
self.wasm_method.into()
|
||||
crate::execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy)
|
||||
}
|
||||
|
||||
/// Enable overriding on-chain WASM with locally-stored WASM
|
||||
|
||||
Reference in New Issue
Block a user