All Projects → rustwasm → Wee_alloc

rustwasm / Wee_alloc

Licence: mpl-2.0
The Wasm-Enabled, Elfin Allocator

Programming Languages

rust
11053 projects

Labels

Projects that are alternatives of or similar to Wee alloc

Wasmer Ruby
💎🕸 WebAssembly runtime for Ruby
Stars: ✭ 286 (-28.32%)
Mutual labels:  wasm
Wasm3
🚀 The fastest WebAssembly interpreter, and the most universal runtime
Stars: ✭ 4,375 (+996.49%)
Mutual labels:  wasm
Wac
WebAssembly interpreter in C
Stars: ✭ 372 (-6.77%)
Mutual labels:  wasm
Highway
Performance-portable, length-agnostic SIMD with runtime dispatch
Stars: ✭ 301 (-24.56%)
Mutual labels:  wasm
Awesome Wasi
😎 Curated list of awesome things regarding WebAssembly WASI ecosystem.
Stars: ✭ 319 (-20.05%)
Mutual labels:  wasm
Unrust
unrust - A pure rust based (webgl 2.0 / native) game engine
Stars: ✭ 341 (-14.54%)
Mutual labels:  wasm
Wasabi
A dynamic analysis framework for WebAssembly programs.
Stars: ✭ 279 (-30.08%)
Mutual labels:  wasm
Ffmpeg.wasm
FFmpeg for browser and node, powered by WebAssembly
Stars: ✭ 6,566 (+1545.61%)
Mutual labels:  wasm
Wasm Pack
This tool seeks to be a one-stop shop for building and working with rust- generated WebAssembly that you would like to interop with JavaScript, in the browser or with Node.js. wasm-pack helps you build rust-generated WebAssembly packages that you could publish to the npm registry, or otherwise use alongside any javascript packages in workflows that you already use, such as webpack.
Stars: ✭ 3,848 (+864.41%)
Mutual labels:  wasm
Awesome Yew
😎 A curated list of awesome things related to Yew / WebAssembly.
Stars: ✭ 353 (-11.53%)
Mutual labels:  wasm
Pigo
Fast face detection, pupil/eyes localization and facial landmark points detection library in pure Go.
Stars: ✭ 3,542 (+787.72%)
Mutual labels:  wasm
Parity Wasm
WebAssembly serialization/deserialization in rust
Stars: ✭ 314 (-21.3%)
Mutual labels:  wasm
Nimtorch
PyTorch - Python + Nim
Stars: ✭ 346 (-13.28%)
Mutual labels:  wasm
Ant Design Blazor
🌈A set of enterprise-class UI components based on Ant Design and Blazor WebAssembly.
Stars: ✭ 3,890 (+874.94%)
Mutual labels:  wasm
Lys
⚜︎ A language that compiles to WebAssembly
Stars: ✭ 375 (-6.02%)
Mutual labels:  wasm
Modfy.video
A video transcoder and converter built using Web Assembly and FFMPEG to transcode and convert videos right in your browser while protecting your privacy
Stars: ✭ 283 (-29.07%)
Mutual labels:  wasm
Platon Go
Golang implementation of the PlatON protocol
Stars: ✭ 331 (-17.04%)
Mutual labels:  wasm
Trunk
Build, bundle & ship your Rust WASM application to the web.
Stars: ✭ 378 (-5.26%)
Mutual labels:  wasm
Lucet
Lucet, the Sandboxing WebAssembly Compiler.
Stars: ✭ 4,006 (+904.01%)
Mutual labels:  wasm
React Wasm
Declarative WebAssembly instantiation for React
Stars: ✭ 349 (-12.53%)
Mutual labels:  wasm

wee_alloc

The Wasm-Enabled, Elfin Allocator

Build Status Build Status Crates.io version Download docs.rs docs

API Docs | Contributing | Chat

Built with 🦀🕸 by The Rust and WebAssembly Working Group

About

wee_alloc: The Wasm-Enabled, Elfin Allocator.

  • Elfin, i.e. small: Generates less than a kilobyte of uncompressed WebAssembly code. Doesn't pull in the heavy panicking or formatting infrastructure. wee_alloc won't bloat your .wasm download size on the Web.

  • WebAssembly enabled: Designed for the wasm32-unknown-unknown target and #![no_std].

wee_alloc is focused on targeting WebAssembly, producing a small .wasm code size, and having a simple, correct implementation. It is geared towards code that makes a handful of initial dynamically sized allocations, and then performs its heavy lifting without any further allocations. This scenario requires some allocator to exist, but we are more than happy to trade allocation performance for small code size. In contrast, wee_alloc would be a poor choice for a scenario where allocation is a performance bottleneck.

Although WebAssembly is the primary target, wee_alloc also has an mmap based implementation for unix systems, a VirtualAlloc implementation for Windows, and a static array-based backend for OS-independent environments. This enables testing wee_alloc, and code using wee_alloc, without a browser or WebAssembly engine.

wee_alloc compiles on stable Rust 1.33 and newer.

Using wee_alloc as the Global Allocator

extern crate wee_alloc;

// Use `wee_alloc` as the global allocator.
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

cargo Features

  • size_classes: On by default. Use size classes for smaller allocations to provide amortized O(1) allocation for them. Increases uncompressed .wasm code size by about 450 bytes (up to a total of ~1.2K).

  • extra_assertions: Enable various extra, expensive integrity assertions and defensive mechanisms, such as poisoning freed memory. This incurs a large runtime overhead. It is useful when debugging a use-after-free or wee_alloc itself.

  • static_array_backend: Force the use of an OS-independent backing implementation with a global maximum size fixed at compile time. Suitable for deploying to non-WASM/Unix/Windows #![no_std] environments, such as on embedded devices with esoteric or effectively absent operating systems. The size defaults to 32 MiB (33554432 bytes), and may be controlled at build-time by supplying an optional environment variable to cargo, WEE_ALLOC_STATIC_ARRAY_BACKEND_BYTES. Note that this feature requires nightly Rust.

  • nightly: Enable usage of nightly-only Rust features, such as implementing the Alloc trait (not to be confused with the stable GlobalAlloc trait!)

Implementation Notes and Constraints

  • wee_alloc imposes two words of overhead on each allocation for maintaining its internal free lists.

  • Deallocation is an O(1) operation.

  • wee_alloc will never return freed pages to the WebAssembly engine / operating system. Currently, WebAssembly can only grow its heap, and can never shrink it. All allocated pages are indefinitely kept in wee_alloc's internal free lists for potential future allocations, even when running on unix targets.

  • wee_alloc uses a simple, first-fit free list implementation. This means that allocation is an O(n) operation.

    Using the size_classes feature enables extra free lists dedicated to small allocations (less than or equal to 256 words). The size classes' free lists are populated by allocating large blocks from the main free list, providing amortized O(1) allocation time. Allocating from the size classes' free lists uses the same first-fit routines that allocating from the main free list does, which avoids introducing more code bloat than necessary.

Finally, here is a diagram giving an overview of wee_alloc's implementation:

+------------------------------------------------------------------------------+
| WebAssembly Engine / Operating System                                        |
+------------------------------------------------------------------------------+
                   |
                   |
                   | 64KiB Pages
                   |
                   V
+------------------------------------------------------------------------------+
| Main Free List                                                               |
|                                                                              |
|          +------+     +------+     +------+     +------+                     |
| Head --> | Cell | --> | Cell | --> | Cell | --> | Cell | --> ...             |
|          +------+     +------+     +------+     +------+                     |
|                                                                              |
+------------------------------------------------------------------------------+
                   |                                    |            ^
                   |                                    |            |
                   | Large Blocks                       |            |
                   |                                    |            |
                   V                                    |            |
+---------------------------------------------+         |            |
| Size Classes                                |         |            |
|                                             |         |            |
|             +------+     +------+           |         |            |
| Head(1) --> | Cell | --> | Cell | --> ...   |         |            |
|             +------+     +------+           |         |            |
|                                             |         |            |
|             +------+     +------+           |         |            |
| Head(2) --> | Cell | --> | Cell | --> ...   |         |            |
|             +------+     +------+           |         |            |
|                                             |         |            |
| ...                                         |         |            |
|                                             |         |            |
|               +------+     +------+         |         |            |
| Head(256) --> | Cell | --> | Cell | --> ... |         |            |
|               +------+     +------+         |         |            |
|                                             |         |            |
+---------------------------------------------+         |            |
                      |            ^                    |            |
                      |            |                    |            |
          Small       |      Small |        Large       |      Large |
          Allocations |      Frees |        Allocations |      Frees |
                      |            |                    |            |
                      |            |                    |            |
                      |            |                    |            |
                      |            |                    |            |
                      |            |                    |            |
                      V            |                    V            |
+------------------------------------------------------------------------------+
| User Application                                                             |
+------------------------------------------------------------------------------+

License

Licensed under the Mozilla Public License 2.0.

TL;DR?

Permissions of this weak copyleft license are conditioned on making available source code of licensed files and modifications of those files under the same license (or in certain cases, one of the GNU licenses). Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. However, a larger work using the licensed work may be distributed under different terms and without source code for files added in the larger work.

Contribution

See CONTRIBUTING.md for hacking!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].