Skip to content
This repository was archived by the owner on Oct 3, 2025. It is now read-only.

Commit 4c9385d

Browse files
chore: improve docs
Signed-off-by: Henry Gressmann <[email protected]>
1 parent b0b4eba commit 4c9385d

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

ARCHITECTURE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Some key differences are:
1212
- TinyWasm is architectured to allow for a JIT compiler to be added later. Functions are stored as FunctionInstances which can contain either a `WasmFunction` or a `HostFunction`. A third variant `JitFunction` could be added later to store a pointer to the compiled function. This would allow for the JIT to be used transparently without changing the rest of the runtime.
1313
- TinyWasm is designed to be used in `no_std` environments. The `std` feature is enabled by default, but can be disabled to remove the dependency on `std` and `std::io`. This is done by disabling the `std` and `parser` features. The `logging` feature can also be disabled to remove the dependency on `log`. This is not recommended, since `libm` is not as performant as the compiler's math intrinsics, especially on wasm32 targets, but can be useful for resource-constrained devices or other environments where `std` is not available such as OS kernels.
1414
- Call Frames are executed in a loop instead of recursively. This allows the use of a single stack for all frames and makes it easier to pause execution and resume it later, or to step through the code one instruction at a time.
15+
- While other interpreters convert `locals` to be register-based when parsing the function body, TinyWasm keeps them in a stack. This is mostly for simplicity in the implementation, but performance is still comparable or better than other interpreters.
1516

1617
## Bytecode Format
1718

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@
55
<h1>TinyWasm</h1>
66
A tiny WebAssembly Runtime written in Rust
77
</div>
8-
8+
99
<br>
1010

1111
[![docs.rs](https://img.shields.io/docsrs/tinywasm?logo=rust)](https://docs.rs/tinywasm) [![Crates.io](https://img.shields.io/crates/v/tinywasm.svg?logo=rust)](https://crates.io/crates/tinywasm) [![Crates.io](https://img.shields.io/crates/l/tinywasm.svg)](./LICENSE-APACHE)
1212

13+
# Why TinyWasm?
14+
15+
- **Tiny** - Designed to be as small as possible without sacrificing too much performance or functionality.
16+
- **Fast enough** - TinyWasm is reasonably fast, especially when compared to other interpreters. See [Performance](#performance) for more details.
17+
- **Portable** - Runs on any platform llvm supports, including WebAssembly. Minimal external dependencies.
18+
1319
# Status
1420

1521
TinyWasm, starting from version `0.3.0`, passes all the WebAssembly 1.0 tests in the [WebAssembly Test Suite](https://github.com/WebAssembly/testsuite). The 2.0 tests are in progress. This is enough to run most WebAssembly programs, including TinyWasm itself compiled to WebAssembly (see [examples/wasm-rust.rs](./examples/wasm-rust.rs)).
1622

1723
Some APIs to interact with the runtime are not yet exposed, and the existing ones are subject to change, but the core functionality is mostly complete.
1824
Results of the tests can be found [here](https://github.com/explodingcamera/tinywasm/tree/main/crates/tinywasm/tests/generated).
1925

20-
TinyWasm is not designed for performance, but rather for size and portability. However, it is still reasonably fast.
26+
TinyWasm is not designed for performance, but rather for simplicity, size and portability. However, it is still reasonably fast, especially when compared to other interpreters. See [Performance](#performance) for more details.
2127

2228
## Supported Proposals
2329

benches/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
# Benchmark results
22

3+
All benchmarks are run on a Ryzen 7 5800X, with 32GB of RAM, running Linux 6.6 with `intel_pstate=passive split_lock_detect=off mitigations=off`.
4+
5+
## Results
6+
37
Coming soon.
48

5-
# Benchmarking
9+
## WebAssembly Settings
10+
11+
All WebAssembly files are compiled with the following settings:
12+
13+
- `opt-level` is set to 3, `lto` is set to `thin`, `codegen-units` is set to 1.
14+
- `reference-types`, `bulk-memory`, `mutable-globals` proposals are enabled.
15+
16+
## Runtime Settings
17+
18+
All runtimes are compiled with the following settings:
19+
20+
- `unsafe` features are enabled
21+
- `opt-level` is set to 3, `lto` is set to `thin`, `codegen-units` is set to 1.
22+
23+
## Benchmarking
624

725
Benchmarks are run using [Criterion.rs](https://github.com/bheisler/criterion.rs) and can be found in the `benches` directory.
826

examples/rust/build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ exclude_wat=("tinywasm")
66
out_dir="./target/wasm32-unknown-unknown/wasm"
77
dest_dir="out"
88

9+
features="+reference-types,+bulk-memory,+mutable-globals"
10+
911
# ensure out dir exists
1012
mkdir -p "$dest_dir"
1113

1214
for bin in "${bins[@]}"; do
13-
RUSTFLAGS="-C target-feature=+reference-types,+bulk-memory -C panic=abort" cargo build --target wasm32-unknown-unknown --package rust-wasm-examples --profile=wasm --bin "$bin"
15+
RUSTFLAGS="-C target-feature=$features -C panic=abort" cargo build --target wasm32-unknown-unknown --package rust-wasm-examples --profile=wasm --bin "$bin"
1416

1517
cp "$out_dir/$bin.wasm" "$dest_dir/"
1618
wasm-opt "$dest_dir/$bin.wasm" -o "$dest_dir/$bin.wasm" -O --intrinsic-lowering -O

examples/rust/src/fibonacci.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ pub extern "C" fn fibonacci(n: i32) -> i32 {
1919
}
2020
sum
2121
}
22+
23+
#[no_mangle]
24+
pub extern "C" fn fibonacci_recursive(n: i32) -> i32 {
25+
if n <= 1 {
26+
return n;
27+
}
28+
fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2)
29+
}

0 commit comments

Comments
 (0)