| Crates.io | bhc-arena |
| lib.rs | bhc-arena |
| version | 0.2.1 |
| created_at | 2026-01-25 17:28:55.116428+00 |
| updated_at | 2026-01-25 18:22:40.529327+00 |
| description | Arena allocators for efficient compiler data structure allocation |
| homepage | |
| repository | https://github.com/raskell-io/bhc |
| max_upload_size | |
| id | 2069133 |
| size | 17,850 |
Arena allocators for efficient compiler data structure allocation.
This crate provides arena allocators that enable fast allocation of compiler data structures with automatic bulk deallocation. Arenas are ideal for per-function or per-module compiler passes where many allocations have the same lifetime.
| Type | Description |
|---|---|
Arena |
Thread-local arena for fast, scoped allocations with byte tracking |
DroplessArena |
Arena for types that don't need destructors (more efficient) |
SyncArena |
Thread-safe arena that can be shared across threads |
Bump |
Re-exported from bumpalo for direct bump allocation |
TypedArena<T> |
Re-exported from typed_arena for type-specific arenas |
use bhc_arena::Arena;
let arena = Arena::new();
// Allocate values - they live until the arena is dropped
let x = arena.alloc(42);
let y = arena.alloc("hello");
// Allocate slices
let slice = arena.alloc_slice(&[1, 2, 3, 4, 5]);
// Allocate from iterators
let from_iter = arena.alloc_from_iter(0..10);
// Track allocation statistics
println!("Bytes allocated: {}", arena.bytes_allocated());
Arena allocation is O(1) bump-pointer allocation, making it significantly faster than individual heap allocations for compiler workloads:
| Scenario | Recommended Arena |
|---|---|
| Per-function IR nodes | Arena |
| Interned strings | DroplessArena |
| Shared across threads | SyncArena |
| Single type, many instances | TypedArena<T> |
DroplessArena is more efficient for Copy types as it skips destructor trackingSyncArena uses internal locking and is safe for concurrent usebhc-intern - Uses arenas for string interning storagebhc-ast - Uses arenas for AST node allocationbhc-core - Uses arenas for Core IR allocation