memkit-async
Task-Local, Async-Native Memory Management for Rust.
โก The Async Challenge
In traditional Rust async, using stack-based or frame-based allocators is dangerous. Resuming a task on a different thread or after a lifetime has expired leads to undefined behavior.
memkit-async solves this by introducing Task-Local Allocation Contexts. Your memory remains valid and local to the logical task, even as it migrates across the thread pool of an executor like tokio.
๐ The Async Advantage
| Feature | Standard Box |
memkit-async |
|---|---|---|
| Fragmentation | High (Global Heap) | Zero (Task Arenas) |
| Locality | Cache-indifferent | High (Contiguous) |
| Safety | Runtime-only | Compile-time & Task-local |
| Pipelining | Locks on contention | Lock-free via Locality |
โจ Features
- ๐งถ Task-Local Arenas โ Each async task gets its own isolated, high-speed allocation context.
- ๐ Backpressure Semantics โ Configurable behavior (
Wait,Fail,Timeout) when memory limits are reached. - ๐ฆ Lock-Free Object Pools โ High-performance object reuse with async acquisition.
- ๐ Zero-Copy Channels โ Move ownership of entire arenas between tasks without a single mem-copy.
- ๐ก๏ธ Await-Safe โ Integrated with the task lifecycle to ensure memory remains valid across
.await.
๐ ๏ธ Quick Start
use ;
async
๐๏ธ Backpressure Policies
When your async tasks are memory-hungry, memkit-async keeps the system stable:
| Policy | Behavior |
|---|---|
Wait |
Suspends the task until memory is available. |
Fail |
Immediately returns a CapacityReached error. |
Timeout |
Waits for a duration before failing. |
Evict |
Discards the oldest entries (useful for caches). |
๐ Integration
Enable the tokio feature for first-class support for the Tokio runtime:
[]
= { = "0.1.1-beta.1", = ["tokio"] }
โ๏ธ License
Licensed under the Mozilla Public License 2.0. See LICENSE.md for details.