Skip to content
This repository was archived by the owner on Oct 3, 2025. It is now read-only.
Closed
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
118 changes: 118 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion crates/tinywasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ criterion={workspace=true}
owo-colors={version="4.0"}
serde_json={version="1.0"}
serde={version="1.0", features=["derive"]}
postcard={version="1.1.1", features = ["use-std"]}
heapless="0.7.17"

[features]
default=["std", "parser", "logging", "archive"]
default=["std", "parser", "logging", "archive", "serde"]
logging=["log", "tinywasm-parser?/logging", "tinywasm-types/logging"]
std=["tinywasm-parser?/std", "tinywasm-types/std"]
parser=["dep:tinywasm-parser"]
archive=["tinywasm-types/archive"]
serde=["tinywasm-types/serde"]

[[test]]
name="test-wasm-1"
Expand Down
13 changes: 13 additions & 0 deletions crates/tinywasm/benches/argon2id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@ fn argon2id_to_twasm(module: TinyWasmModule) -> Result<AlignedVec> {
Ok(twasm)
}

fn argon2id_to_postcard_wasm(module: TinyWasmModule) -> Result<Vec<u8>> {
let postcard_wasm = postcard::to_stdvec(&module)?;
Ok(postcard_wasm)
}

fn argon2id_from_twasm(twasm: AlignedVec) -> Result<TinyWasmModule> {
let module = TinyWasmModule::from_twasm(&twasm)?;
Ok(module)
}

fn argon2id_from_postcard_wasm(postcard_wasm: Vec<u8>) -> Result<TinyWasmModule> {
let module = postcard::from_bytes(&postcard_wasm)?;
Ok(module)
}

fn argon2id_run(module: TinyWasmModule) -> Result<()> {
let mut store = Store::default();
let instance = ModuleInstance::instantiate(&mut store, module.into(), None)?;
Expand All @@ -32,10 +42,13 @@ fn argon2id_run(module: TinyWasmModule) -> Result<()> {
fn criterion_benchmark(c: &mut Criterion) {
let module = argon2id_parse().expect("argon2id_parse");
let twasm = argon2id_to_twasm(module.clone()).expect("argon2id_to_twasm");
let postcard_wasm = argon2id_to_postcard_wasm(module.clone()).expect("argon2id_to_postcard_wasm");

c.bench_function("argon2id_parse", |b| b.iter(argon2id_parse));
c.bench_function("argon2id_to_twasm", |b| b.iter(|| argon2id_to_twasm(module.clone())));
c.bench_function("argon2id_to_postcard_wasm", |b| b.iter(|| argon2id_to_postcard_wasm(module.clone())));
c.bench_function("argon2id_from_twasm", |b| b.iter(|| argon2id_from_twasm(twasm.clone())));
c.bench_function("argon2id_from_postcard_wasm", |b| b.iter(|| argon2id_from_postcard_wasm(postcard_wasm.clone())));
c.bench_function("argon2id", |b| b.iter(|| argon2id_run(module.clone())));
}

Expand Down
15 changes: 15 additions & 0 deletions crates/tinywasm/benches/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@ fn fibonacci_to_twasm(module: TinyWasmModule) -> Result<AlignedVec> {
Ok(twasm)
}

fn fibonacci_to_postcard_wasm(module: TinyWasmModule) -> Result<Vec<u8>> {
let postcard_wasm = postcard::to_stdvec(&module)?;
Ok(postcard_wasm)
}

fn fibonacci_from_twasm(twasm: AlignedVec) -> Result<TinyWasmModule> {
let module = TinyWasmModule::from_twasm(&twasm)?;
Ok(module)
}

fn fibonacci_from_postcard_wasm(postcard_wasm: Vec<u8>) -> Result<TinyWasmModule> {
let module = postcard::from_bytes(&postcard_wasm)?;
Ok(module)
}

fn fibonacci_run(module: TinyWasmModule, recursive: bool, n: i32) -> Result<()> {
let mut store = Store::default();
let instance = ModuleInstance::instantiate(&mut store, module.into(), None)?;
Expand All @@ -38,10 +48,15 @@ fn fibonacci_run(module: TinyWasmModule, recursive: bool, n: i32) -> Result<()>
fn criterion_benchmark(c: &mut Criterion) {
let module = fibonacci_parse().expect("fibonacci_parse");
let twasm = fibonacci_to_twasm(module.clone()).expect("fibonacci_to_twasm");
let postcard_wasm = fibonacci_to_postcard_wasm(module.clone()).expect("fibonacci_to_postcard_wasm");

c.bench_function("fibonacci_parse", |b| b.iter(fibonacci_parse));
c.bench_function("fibonacci_to_twasm", |b| b.iter(|| fibonacci_to_twasm(module.clone())));
c.bench_function("fibonacci_to_postcard_wasm", |b| b.iter(|| fibonacci_to_postcard_wasm(module.clone())));
c.bench_function("fibonacci_from_twasm", |b| b.iter(|| fibonacci_from_twasm(twasm.clone())));
c.bench_function("fibonacci_from_postcard_wasm", |b| {
b.iter(|| fibonacci_from_postcard_wasm(postcard_wasm.clone()))
});
c.bench_function("fibonacci_iterative_60", |b| b.iter(|| fibonacci_run(module.clone(), false, 60)));
c.bench_function("fibonacci_recursive_26", |b| b.iter(|| fibonacci_run(module.clone(), true, 26)));
}
Expand Down
14 changes: 14 additions & 0 deletions crates/tinywasm/benches/tinywasm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use criterion::{criterion_group, criterion_main, Criterion};
use eyre::Result;
use heapless::Vec as HeapLessVec;
use tinywasm::{types, Extern, FuncContext, Imports, ModuleInstance, Store};
use types::{archive::AlignedVec, TinyWasmModule};

Expand All @@ -16,11 +17,21 @@ fn tinywasm_to_twasm(module: TinyWasmModule) -> Result<AlignedVec> {
Ok(twasm)
}

fn tinywasm_to_postcard_wasm(module: TinyWasmModule) -> Result<Vec<u8>> {
let postcard_wasm = postcard::to_stdvec(&module)?;
Ok(postcard_wasm)
}

fn tinywasm_from_twasm(twasm: AlignedVec) -> Result<TinyWasmModule> {
let module = TinyWasmModule::from_twasm(&twasm)?;
Ok(module)
}

fn tinywasm_from_postcard_wasm(postcard_wasm: Vec<u8>) -> Result<TinyWasmModule> {
let module = postcard::from_bytes(&postcard_wasm)?;
Ok(module)
}

fn tinywasm_run(module: TinyWasmModule) -> Result<()> {
let mut store = Store::default();
let mut imports = Imports::default();
Expand All @@ -34,10 +45,13 @@ fn tinywasm_run(module: TinyWasmModule) -> Result<()> {
fn criterion_benchmark(c: &mut Criterion) {
let module = tinywasm_parse().expect("tinywasm_parse");
let twasm = tinywasm_to_twasm(module.clone()).expect("tinywasm_to_twasm");
let postcard_wasm = tinywasm_to_postcard_wasm(module.clone()).expect("tinywasm_to_postcard_wasm");

c.bench_function("tinywasm_parse", |b| b.iter(tinywasm_parse));
c.bench_function("tinywasm_to_twasm", |b| b.iter(|| tinywasm_to_twasm(module.clone())));
c.bench_function("tinywasm_to_postcard_wasm", |b| b.iter(|| tinywasm_to_postcard_wasm(module.clone())));
c.bench_function("tinywasm_from_twasm", |b| b.iter(|| tinywasm_from_twasm(twasm.clone())));
c.bench_function("tinywasm_from_postcard_wasm", |b| b.iter(|| tinywasm_from_postcard_wasm(postcard_wasm.clone())));
c.bench_function("tinywasm", |b| b.iter(|| tinywasm_run(module.clone())));
}

Expand Down
2 changes: 1 addition & 1 deletion crates/tinywasm/src/interpreter/stack/block_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) struct BlockStack(Vec<BlockFrame>);

impl Default for BlockStack {
fn default() -> Self {
Self(Vec::with_capacity(128))
Self(Vec::with_capacity(0))
}
}

Expand Down
14 changes: 7 additions & 7 deletions crates/tinywasm/src/interpreter/stack/value_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use tinywasm_types::{ExternRef, FuncRef, ValType, ValueCounts, ValueCountsSmall,
use crate::{interpreter::*, Result};

use super::Locals;
pub(crate) const STACK_32_SIZE: usize = 1024 * 32;
pub(crate) const STACK_64_SIZE: usize = 1024 * 16;
pub(crate) const STACK_128_SIZE: usize = 1024 * 8;
pub(crate) const STACK_32_SIZE: usize = 1024;
pub(crate) const STACK_64_SIZE: usize = 1024;
pub(crate) const STACK_128_SIZE: usize = 1024;
pub(crate) const STACK_REF_SIZE: usize = 1024;

#[derive(Debug)]
Expand All @@ -20,10 +20,10 @@ pub(crate) struct ValueStack {
impl ValueStack {
pub(crate) fn new() -> Self {
Self {
stack_32: Vec::with_capacity(STACK_32_SIZE),
stack_64: Vec::with_capacity(STACK_64_SIZE),
stack_128: Vec::with_capacity(STACK_128_SIZE),
stack_ref: Vec::with_capacity(STACK_REF_SIZE),
stack_32: Vec::with_capacity(0),
stack_64: Vec::with_capacity(0),
stack_128: Vec::with_capacity(0),
stack_ref: Vec::with_capacity(0),
}
}

Expand Down
Loading