-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v4.1 - counters, wasm benchmarks, docs, and my axe
- Loading branch information
Showing
30 changed files
with
1,921 additions
and
1,448 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
target | ||
Cargo.lock | ||
|
||
pkg | ||
|
||
*.asm | ||
perf* | ||
flamegraph.svg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,46 @@ | ||
# Talc on WASM | ||
|
||
`Talc` provides a good middleground by being faster than `lol_alloc` and `dlmalloc` while inbetweening them in size, although your mileage will vary. | ||
|
||
If you'd like to see comparisons to other allocators in this space, consider creating a pull request or opening an issue. | ||
`Talc` provides a decent middleground by being faster than `lol_alloc` and `dlmalloc` (Rust WASM default) while inbetweening them in size. Although your mileage will vary, comparison tables are laid out below. | ||
|
||
## Usage | ||
Set the global allocator in your project after running `cargo add talc` as follows: | ||
|
||
```rust | ||
#[global_allocator] static TALC: talc::TalckWasm = unsafe { talc::TalckWasm::new_global() }; | ||
/// SAFETY: | ||
/// The runtime environment must be single-threaded WASM. | ||
/// | ||
/// Note: calls to memory.grow during use of the allocator is allowed. | ||
#[global_allocator] | ||
static ALLOCATOR: talc::TalckWasm = unsafe { talc::TalckWasm::new_global() }; | ||
``` | ||
|
||
Make sure that you have the `lock_api` feature enabled! | ||
- e.g. using stable Rust, in your `Cargo.toml`: `talc = { version = "3", default-features = false, features = ["lock_api"] }` | ||
Config features: | ||
- If default features are disabled, make sure to enable `"lock_api"`. | ||
- Turn on `"counters"` for allocation statistics accessible via `ALLOCATOR.lock().get_counters()` | ||
- You can turn off default features to remove `"nightly_api"`, allowing stable Rust builds. | ||
|
||
Note, this disables `nightly_api`, which isn't used in this API, allowing use of stable Rust. | ||
`default-features = false, features = ["lock_api"]` | ||
|
||
## Relative WASM Binary Size | ||
|
||
Rough measurements of allocator size for relative comparison using `wasm_size.sh` and `wasm-size`. | ||
Rough measurements of allocator size for relative comparison using `wasm-size.sh` + `/wasm-size`. | ||
|
||
| Allocator | Size (bytes) - lower is better | | ||
| --------- | ----- | | ||
| lol_alloc | 18333 | | ||
| talc | 22017 | | ||
| dlmalloc | 23935 | | ||
| lol_alloc | 15689 | | ||
| talc | 19228 | | ||
| dlmalloc (default) | 21316 | | ||
|
||
## WASM Benchmarks | ||
|
||
Rough allocator benchmarks for comparison from [this project](https://github.com/SFBdragon/wasm-alloc-bench). | ||
Rough measurements of allocator speed for relative comparison using `wasm-bench.sh` + `/wasm-bench`. | ||
|
||
| Allocator | Average Time per 100000 actions (ms) - lower is better | | ||
|-----------|--------------| | ||
| talc | 14.9 | | ||
| dlmalloc | 17.6 | | ||
| lol_alloc | 35.4 | | ||
|-----------|-----| | ||
| talc | 15.86 | | ||
| dlmalloc (default) | 18.84 | | ||
| lol_alloc | 34.26 | | ||
|
||
|
||
|
||
If you'd like to see comparisons to other allocators in this space, consider creating a pull request or opening an issue. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
talc,2124135,3414161,5548655,6975498,8757172 | ||
dlmalloc,1751668,3010320,4297688,5617197,6864423 | ||
buddy_alloc,1857310,3287706,4827965,5416634,6440880 | ||
galloc,1499908,3021132,4449615,5866347,7214401 | ||
linked_list_allocator,721875,1268446,1744086,1501040,2072381 | ||
talc,2064640,3909176,5728649,7109421,8674172 | ||
dlmalloc,1839576,3271813,4653826,5833814,7605962 | ||
buddy_alloc,1832692,3029561,4986008,5546652,6890189 | ||
galloc,1462284,2881406,4347195,5752558,7009735 | ||
linked_list_allocator,744979,1212205,1185165,1455435,2023988 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.