Skip to content

N43: blink-alloc #1298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions content/news/043/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,57 @@ generated Metal/GLSL preview.
[web demo]: https://not-fl3.github.io/miniquad-samples/shadertoy_cross.html
[macroquad-shadertoy]: https://github.com/not-fl3/macroquad/blob/master/examples/shadertoy.rs

### [blink-alloc]

[blink-alloc] is a brand new arena-allocator with bunch of improvements
over existing solutions that is
tested with [Miri] and follows ["Strict Provenance Rules"][strict-provenance].

> Arena-allocators offer extremely fast allocations and deallocations.
> Allocation is just a few pointer arithmetic operations.
> And deallocation is nearly no-op.
> In exchange arena-allocator requires a point in time when all
> previous allocations are unused to reset state.\
> Rust's borrow-checker ensures the requirement for reset making
> it 100% safe to use.
>
> TL;DR great for games, servers, cli tools and more.

blink-alloc provides thread-local and multi-threaded allocators -
`BlinkAlloc` and `SyncBlinkAlloc`.
Single-threaded version [performs many times faster than `bumpalo`][blink-bench].
The author couldn't find another implementation to compare
the multi-threaded version's performance.

It also provided ouf-of-the-box to fetch `BlinkAlloc` in task/thread
and return it back when done, keeping multiple `BlinkAlloc` instanced warmed.

On top of raw allocations blink-alloc provides `Blink` type
that works as safe allocator adaptor.
`Blink` can allocate memory and initialize it with values provided by user.
User may provide values as-is, as closures or iterators.
`Blink`'s API is safe with few exception for niche use cases.

Those familiar with `bumpalo` may think of `Blink` as of `bumpalo::Bump`.
Though `Blink`

- drops all placed values on reset,
which makes it usable with any kind of types without resource leaks.
- Accepts any iterator type, not just `ExactSizeIterator` implementations.
- Is configurable to use any `BlinkAllocator` implementation, thus not
tied to `Global`.

Currently Rust's standard collection types may use custom allocators
only one nightly and with `allocator_api` feature enabled.
blink-alloc uses `allocator-api2` crate to work on both stable and nightly.
Integration with other crates is simple and doesn't require depending on
blink-alloc, only on `allocator-api2`.

[blink-alloc]: https://github.com/zakarumych/blink-alloc
[blink-bench]: https://github.com/zakarumych/blink-alloc/blob/main/BENCHMARKS.md
[Miri]: https://github.com/rust-lang/miri
[strict-provenance]: https://github.com/rust-lang/rust/issues/95228

## Popular Workgroup Issues in Github

<!-- Up to 10 links to interesting issues -->
Expand Down