Skip to content
Draft
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
if: github.event_name == 'push'
runs-on: ubuntu-amd64-8core
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run Criterion (save baseline "devel")
Expand Down Expand Up @@ -40,14 +40,14 @@ jobs:
contents: read
pull-requests: write # needed to comment on PRs (won’t work for forks; see note below)
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2

# Try to fetch the latest successful baseline from devel
- name: Download baseline from devel
id: dl
uses: dawidd6/action-download-artifact@v3
uses: dawidd6/action-download-artifact@v11
continue-on-error: true # allow first PRs without a baseline
with:
workflow: bench.yml
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ libm = "0.2.1"
smallvec = "1.15.0"
num-derive = "0.4.2"
spin = "0.10.0"
fnv = { version = "1.0.7", default-features = false }

# tracing
serde = { version = "1.0.219", features = ["derive"], optional = true }

# wasmtime
wasmtime = { git = "https://github.com/fluentlabs-xyz/wasmtime", branch = "devel", optional = true, features = ["disable-fpu", "cache"] }
#wasmtime = { path = "../wasmtime/crates/wasmtime", optional = true, features = ["disable-fpu"] }
#wasmtime = { path = "../wasmtime/crates/wasmtime", optional = true, features = ["disable-fpu", "cache"] }
anyhow = { version = "1.0.98", default-features = false, optional = true }
directories = { version = "6.0.0", optional = true }
futures = { version = "0.3.31", optional = true }

# wasmi
wasmi = { version = "0.47.0", default-features = false }
libc = { version = "0.2.172", default-features = false, features = ["align", "extra_traits", "const-extern-fn"] }

[dev-dependencies]
rand = "0.9.1"
Expand All @@ -51,14 +53,23 @@ std = [
"num-traits/std",
"bitvec/std",
"wasmtime?/std",
"unix-memory",
"pooling-allocator",
]
more-max-pages = []
serde = [
"dep:serde", "serde/derive"
]
tracing = ["serde"]
debug-print = []
test-build = []
debug-print = ["std"]
fpu = []
wasmtime = ["dep:wasmtime", "dep:anyhow", "dep:futures"]
cache-compiled-artifacts = ["wasmtime", "dep:directories"]
pooling-allocator = []
pooling-allocator = []
unix-memory = []

[[test]]
name = "integration"
path = "tests/snippets.rs"
required-features = ["test-build"]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ clean:
# Delete all Cargo.lock files except the root
find . -name Cargo.lock ! -path './Cargo.lock' -type f -exec rm -f {} +

.PHONY: test
test:
cargo test

all: test-specific-cases
2 changes: 1 addition & 1 deletion benchmarks/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target
Cargo.lock
lib.wat
lib.wasm
lib.wasm
40 changes: 35 additions & 5 deletions benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,42 @@ debug-assertions = false
rpath = false
codegen-units = 1

[dependencies]
criterion = { version = "0.7.0", default-features = false, features = [] }

[dev-dependencies]
criterion = { version = "0.7.0", default-features = false, features = [] }
rwasm = { path = "..", features = ["std", "wasmtime"] }
rand = { version = "0.9.2" }
wat = "1.230.0"
bitvec = { version = "1.0.1", default-features = false, features = ["alloc"] }
revm-interpreter = "25.0.3"
revm-bytecode = "6.2.2"
hex-literal = "1.0.0"

[[bench]]
name = "bench"
harness = false
name = "bitvec"
harness = false

[[bench]]
name = "compilation"
harness = false

[[bench]]
name = "fib32"
harness = false

[[bench]]
name = "fib64"
harness = false

[[bench]]
name = "fib256"
harness = false

[[bench]]
name = "parsing"
harness = false

[dependencies]
alloy-primitives = { version = "1.4.0", default-features = false }

[features]
default = ["rwasm/unix-memory"]
4 changes: 2 additions & 2 deletions benchmarks/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: build
build:
RUSTFLAGS="-C link-arg=-zstack-size=0" cargo b --target=wasm32-unknown-unknown --release --no-default-features
RUSTFLAGS="-C link-arg=-zstack-size=1024" cargo b --target-dir=./target --target=wasm32-unknown-unknown --release --no-default-features
cp ./target/wasm32-unknown-unknown/release/fib.wasm ./lib.wasm
wasm2wat ./lib.wasm > ./lib.wat || true
wasm2wat ./lib.wasm > ./lib.wat || true
98 changes: 0 additions & 98 deletions benchmarks/benches/bench.rs

This file was deleted.

109 changes: 109 additions & 0 deletions benchmarks/benches/bitvec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use bitvec::{order::Lsb0, vec::BitVec};
use criterion::{criterion_main, Criterion};
use rwasm::{
bitvec_inlined::{BitVecInlined, USIZE_BITS},
CompilationConfig, ExecutionEngine, RwasmModule, RwasmStore, Value,
};
use std::time::Duration;

fn bench_comparisons(c: &mut Criterion) {
let mut group = c.benchmark_group("Comparisons");

const BITVEC_STORE_COUNT: usize = 1;
const BITVEC_INLINED_STORE_COUNT: usize = BITVEC_STORE_COUNT;
const BITVEC_INLINED_STORE_COUNT_HALF: usize = BITVEC_STORE_COUNT / 2;
let bitvec_bits = USIZE_BITS * BITVEC_STORE_COUNT;
let random_sets_count = 1000;
let random_idxs_values =
core::iter::repeat_with(|| (rand::random_range(..bitvec_bits), rand::random::<bool>()))
.take(random_sets_count)
.collect::<Vec<_>>();

// bitvec
{
group.bench_function("bitvec", |b| {
b.iter(|| {
for i in 0..random_sets_count {
let mut bv = BitVec::<usize, Lsb0>::repeat(true, bitvec_bits);
let (idx, value) = random_idxs_values[i];
bv.set(idx, value);
core::hint::black_box(bv);
}
});
});
};

// bitvec_inlined
{
group.bench_function("bitvec_inlined", |b| {
b.iter(|| {
for i in 0..random_sets_count {
let mut bv =
BitVecInlined::<{ BITVEC_INLINED_STORE_COUNT }>::repeat(true, bitvec_bits);
let (idx, value) = random_idxs_values[i];
bv.set(idx, value);
core::hint::black_box(bv);
}
});
});
};

// bitvec_inlined (half store)
{
let mut bv =
BitVecInlined::<{ BITVEC_INLINED_STORE_COUNT_HALF }>::repeat(true, bitvec_bits);
group.bench_function("bitvec_inlined (half of inline store)", |b| {
b.iter(|| {
for i in 0..random_sets_count {
let (idx, value) = random_idxs_values[i];
bv.set(idx, value);
}
});
});
};

{
let wasm_binary = wat::parse_str(
r#"
(module
(memory 1)
(data (i32.const 0) "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzab")
(func (export "64_good1") (param $i i32) (result i64)
(i64.load offset=0 (local.get $i)) ;; 0x6867666564636261 'abcdefgh'
)
)
"#,
)
.unwrap();
let config = CompilationConfig::default()
.with_entrypoint_name("64_good1".into())
.with_allow_malformed_entrypoint_func_type(true);
let (rwasm_module, _) = RwasmModule::compile(config, &wasm_binary).unwrap();
println!("{}", rwasm_module);
let mut store = RwasmStore::<()>::default();
let engine = ExecutionEngine::new();
let mut result = [Value::I64(0); 1];
group.bench_function("bitvec_inlined (through ExecutionEngine)", |b| {
b.iter(|| {
for _ in 0..random_sets_count {
engine
.execute(&mut store, &rwasm_module, &[Value::I32(0)], &mut result)
.unwrap();
assert_eq!(result[0].i64().unwrap(), 0x6867666564636261);
}
});
});
};

group.finish();
}

pub fn benches() {
let mut criterion: Criterion<_> = Criterion::default()
.configure_from_args()
.warm_up_time(Duration::from_millis(500))
.measurement_time(Duration::from_secs(1))
.sample_size(200);
bench_comparisons(&mut criterion);
}
criterion_main!(benches);
Loading