diff --git a/Cargo.lock b/Cargo.lock index c220f496b0..084a2cb0a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1964,6 +1964,18 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" +[[package]] +name = "shuffling-allocator" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "848c0a454373d16ebfaa740c99d4faebe25ea752a35e0c6e341168fe67f987f8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "rand", + "winapi", +] + [[package]] name = "smallvec" version = "1.6.1" @@ -2430,6 +2442,7 @@ name = "wasmtime-bench-api" version = "0.19.0" dependencies = [ "anyhow", + "shuffling-allocator", "wasi-common", "wasmtime", "wasmtime-wasi", diff --git a/crates/bench-api/Cargo.toml b/crates/bench-api/Cargo.toml index 02dfd986be..c5c70bf6df 100644 --- a/crates/bench-api/Cargo.toml +++ b/crates/bench-api/Cargo.toml @@ -16,10 +16,13 @@ crate-type = ["rlib", "cdylib"] [dependencies] anyhow = "1.0" +shuffling-allocator = { version = "1.1.1", optional = true } wasmtime = { path = "../wasmtime", default-features = false } wasmtime-wasi = { path = "../wasi" } wasi-common = { path = "../wasi-common" } - [dev-dependencies] wat = "1.0" + +[features] +default = ["shuffling-allocator"] diff --git a/crates/bench-api/src/lib.rs b/crates/bench-api/src/lib.rs index a2958f09a8..8daf1197d8 100644 --- a/crates/bench-api/src/lib.rs +++ b/crates/bench-api/src/lib.rs @@ -83,6 +83,14 @@ pub type ExitCode = c_int; pub const OK: ExitCode = 0; pub const ERR: ExitCode = -1; +// Randomize the location of heap objects to avoid accidental locality being an +// uncontrolled variable that obscures performance evaluation in our +// experiments. +#[cfg(feature = "shuffling-allocator")] +#[global_allocator] +static ALLOC: shuffling_allocator::ShufflingAllocator = + shuffling_allocator::wrap!(&std::alloc::System); + /// Exposes a C-compatible way of creating the engine from the bytes of a single /// Wasm module. ///