rustc-arena-modified: rustc-arena ported to stable rust with additional features
Forked from rustc_arena
Why would you want this?
- Allocating objects in an arena can be faster then regular allocation
- An arena doubles as a collection where you can insert objects behind a shared reference. Instead of
Cloneing objects and possibly usingRcs, use anArenaand copy the references.
What about typed-arena and bumpalo?
rustc_arena_modified::TypedArenaallows coalescing and clearing objects behind a mutable reference, while saving the chunks so they don't need to be re-allocated. This is equivalent to callinginto_vecand then converting the vector back into an arena, but faster, because you don't need to allocate anything.rustc_arena_modified::TypedArenais also significantly faster at iteration according to the benchmarks (other differences are negligible; see benchmarks)rustc_arena_modified::TypedArenareturns a shared reference to allocated values, so it can iterate values behind a shared reference liketyped-arena-nomut. Unliketyped-arena-nomut, it can also be no-op converted betweenrustc_arena_modified::TypedArenaMut, which is the same but returns mutable references. And, you can get iterate mutable element references behind a mutable reference to even the shared arena, because that ensures there are no active shared references.- The
slabfeature providesSlabArena, a wrapper forrustc_arena_modified::TypedArenawhich makes it keep track of freed elements in a linked list so their memory can be reclaimed. This comes with some drawbacks, like the inability to allocate slices in the free list (???: allow slice allocation, just make it not part of the free list?) - TODO: Comparisons between
DroplessArenaandBump(note: maybeBumpis objectively better)
What is it?
A port of rustc_arena into stable rust with the following new features:
TypedArena::iterto iterate over all objects in the arenaTypedArena::retainandTypedArena::clearto coalesce clearing objects behind a mutable reference, while saving the chunks so they don't need to be re-allocated.
Safety
This library makes heavy use of unsafe and isn't fully tested with MIRI. There are tests for most operations and edge cases, and the base functionality is copied almost verbatim from rustc_arena which is very well-tested. But the extra functionality is much less tested, and especially with the heavy use of unsafe, it shouldn't be used in production.
Benchmarks
Overall, performs around the same speed as rustc_arena and typed_arena, except iteration is significantly faster than typed_arena. slab_arena performs noticeably slower.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Forked from rustc-arena (Github), which is also licensed under MIT "or" Apache 2.0.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.