Comments (4)
The dynamic allocation example is measuring a whole lot more than just dynamic allocation: string formatting is rather heavy, and I suspect it is pulling in the panicking infrastructure as well.
If you are trying to specifically measure the code size of allocators, I suggest something more targeted, like https://github.com/rustwasm/wee_alloc/blob/master/example/src/lib.rs
You can built that with the ./build.sh
script in this repo. If size classes are disabled, I get a 1,148 bytes binary, and if I enable size classes, then I get a 1,415 bytes binary (after wasm-gc and wasm-opt):
1148 ../target/wasm32-unknown-unknown/release/wee_alloc_example.gc.opt.wasm
1415 ../target/wasm32-unknown-unknown/release/wee_alloc_example.size_classes.gc.opt.wasm
from wee_alloc.
I have the following lib.rs file:
use wasm_bindgen::prelude::*;
use wee_alloc::WeeAlloc;
// Use `wee_alloc` as the global allocator.
#[global_allocator]
static ALLOC: WeeAlloc = WeeAlloc::INIT;
#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
}
#[wasm_bindgen]
pub fn greet(name: &str) {
alert(name);
}
When I compile that using wasm-pack and then inspect the output using twiggy, I get:
Shallow Bytes │ Shallow % │ Item
───────────────┼───────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1353 ┊ 25.55% ┊ "function names" subsection
1065 ┊ 20.11% ┊ data[0]
580 ┊ 10.95% ┊ <wee_alloc::WeeAlloc as core::alloc::GlobalAlloc>::alloc::h56b2fbb231097050
574 ┊ 10.84% ┊ wee_alloc::alloc_first_fit::hc3745372ad8f8d4e
327 ┊ 6.18% ┊ wee_alloc::WeeAlloc::dealloc_impl::{{closure}}::h92c7acfcf75e2e63
252 ┊ 4.76% ┊ <wee_alloc::size_classes::SizeClassAllocPolicy as wee_alloc::AllocPolicy>::new_cell_for_free_list::h6ef3252c1cc78ab3
176 ┊ 3.32% ┊ <wee_alloc::WeeAlloc as core::alloc::GlobalAlloc>::dealloc::haa7b6f21eac5aae6
121 ┊ 2.29% ┊ <wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::new_cell_for_free_list::h8d68be1a53220a52
113 ┊ 2.13% ┊ custom section 'producers'
80 ┊ 1.51% ┊ data[1]
57 ┊ 1.08% ┊ __rg_realloc
56 ┊ 1.06% ┊ memcpy
47 ┊ 0.89% ┊ __wbindgen_malloc
35 ┊ 0.66% ┊ import wbg::__wbg_alert_e4f89deb17f7e8ca
35 ┊ 0.66% ┊ __wbindgen_realloc
26 ┊ 0.49% ┊ greet
21 ┊ 0.40% ┊ export "__wbindgen_realloc"
21 ┊ 0.40% ┊ __rust_realloc
20 ┊ 0.38% ┊ export "__wbindgen_malloc"
17 ┊ 0.32% ┊ __rust_alloc
319 ┊ 6.02% ┊ ... and 42 more.
5295 ┊ 100.00% ┊ Σ [62 Total Rows]
Rows 3-8 all appear to be wee_alloc, and it adds up to 2030 bytes. That includes size_classes, but still bigger than the 1.2 KB advertised in the README.
It's still much smaller than the default allocator though.
from wee_alloc.
Probably this ticket can be closed now. The size was related to a bug in Rust-lang, as rust kept dependencies to both, wee-alloc and dlmalloc. It was caused by some hard coded function name for an intrinsic in rust-lang, keeping a dependency to dlmalloc.
This caused the Wee-alloc based binary to be even larger than the pure dlmalloc binary.
from wee_alloc.
When building with opt-level = "s"
and then running through wasm-opt -Os
, the size gets smaller. It's hard to tell which symbols are which in the wasm-opt
output, but even just enabling opt-level = "s"
brings the payload down to 1534 bytes. So I guess I just wasn't using opt-level = "s"
earlier.
from wee_alloc.
Related Issues (20)
- Impossibly large allocations fails but still allocates new memory pages
- Cloudflare Worker response bodies being mangled when using wee_alloc HOT 1
- Update outdated usage instruction regarding "extern crate"
- WASM Module HOT 1
- Possible allocator memory corruption? HOT 1
- Unbounded Memory Leak HOT 8
- Is this repo still maintained? HOT 8
- This repo needs to be archived and marked as deprecated HOT 4
- free_cell_layout test fails on macOS HOT 1
- CI doesn't check configuration w/o size_classes
- CI should be running tests HOT 6
- Panicky wasm from Vec allocation HOT 2
- Release new version to crates.io HOT 1
- Add git tag for 0.4.3 HOT 1
- Storage at arbitrary address HOT 2
- wee_alloc leaks memory HOT 5
- Allow heap to start not at a page boundary HOT 2
- Shell scripts of repo not working due to wee_alloc compilation errors HOT 5
- Implement more efficient grow/shrink/realloc methods
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wee_alloc.