Refactor configuration for the pooling allocator (#5205)
This commit changes the APIs in the `wasmtime` crate for configuring the pooling allocator. I plan on adding a few more configuration options in the near future and the current structure was feeling unwieldy for adding these new abstractions. The previous `struct`-based API has been replaced with a builder-style API in a similar shape as to `Config`. This is done to help make it easier to add more configuration options in the future through adding more methods as opposed to adding more field which could break prior initializations.
This commit is contained in:
@@ -202,13 +202,11 @@ fn bench_instantiation(c: &mut Criterion) {
|
||||
fn strategies() -> impl Iterator<Item = InstanceAllocationStrategy> {
|
||||
[
|
||||
InstanceAllocationStrategy::OnDemand,
|
||||
InstanceAllocationStrategy::Pooling {
|
||||
strategy: Default::default(),
|
||||
instance_limits: InstanceLimits {
|
||||
memory_pages: 10_000,
|
||||
..Default::default()
|
||||
},
|
||||
},
|
||||
InstanceAllocationStrategy::Pooling({
|
||||
let mut config = PoolingAllocationConfig::default();
|
||||
config.instance_memory_pages(10_000);
|
||||
config
|
||||
}),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
@@ -91,15 +91,10 @@ fn test_setup() -> (Engine, Module) {
|
||||
// We only expect to create one Instance at a time, with a single memory.
|
||||
let pool_count = 10;
|
||||
|
||||
let mut pool = PoolingAllocationConfig::default();
|
||||
pool.instance_count(pool_count).instance_memory_pages(1);
|
||||
let mut config = Config::new();
|
||||
config.allocation_strategy(InstanceAllocationStrategy::Pooling {
|
||||
strategy: PoolingAllocationStrategy::NextAvailable,
|
||||
instance_limits: InstanceLimits {
|
||||
count: pool_count,
|
||||
memory_pages: 1,
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
|
||||
let engine = Engine::new(&config).unwrap();
|
||||
|
||||
// The module has a memory (shouldn't matter) and a single function which is a no-op.
|
||||
|
||||
Reference in New Issue
Block a user