Skip to content

[RFC 65] Allocator-aware buffers - #65

Open
gatesn wants to merge 1 commit into
developfrom
ngates/buffer-allocation-rfc
Open

[RFC 65] Allocator-aware buffers#65
gatesn wants to merge 1 commit into
developfrom
ngates/buffer-allocation-rfc

Conversation

@gatesn

@gatesn gatesn commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • propose allocator-aware host buffers
  • allocate directly with runtime-aligned layouts
  • keep owned and external buffer backing separate
  • make execution allocation explicit

Checks

  • bunx prettier --check rfcs/0065-buffer-allocation.md
  • bun run build

Signed-off-by: Nicholas Gates <nick@nickgates.com>

A manual ownership vtable could support each backing type. It would also require custom reference
counting, release, and unique-owner recovery. The private backing type lets us add this later if an
`Arc` is too costly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arc is already a huge part of the runtime of scans.

pub struct Buffer<T> {
ptr: NonNull<T>,
len: usize,
alignment: Alignment,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have Alignment and Layout

@joseph-isaacs

Copy link
Copy Markdown
Contributor

Do you have any thought on using this to limit mem allocated for a given region?

@joseph-isaacs

Copy link
Copy Markdown
Contributor

Do we know what the perf change between this and bytes will be.
What would be measure?

@gatesn

gatesn commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Do you have any thought on using this to limit mem allocated for a given region?

ctx.with_allocator(...) and basically direct requests through whatever allocator you're given.

So the host engine and/or runtime could pass in an allocator pinned to a NUMA core.

Functions that e.g. canonicalize list offsets, use them, then throw them away could configure arena allocators.

And most commonly I'd expect the host engine to simply want to use a tree of allocators to track who allocated what.

@gatesn

gatesn commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Do we know what the perf change between this and bytes will be.

What would be measure?

vortex-buffer is actually really well tested and benchmarked.

The first PR in the stack shows a bunch of regressions for example. I believe there's just a bunch of inlining to fix up, but there shouldn't be any more allocations than with Tokio bytes.

The only thing we give up is the split/unsplit functionality. But nothing uses that currently.

@joseph-isaacs

Copy link
Copy Markdown
Contributor

The first PR in the stack shows a bunch of regressions for example. I believe there's just a bunch of inlining to fix up, but there shouldn't be any more allocations than with Tokio bytes.

I would like to avoid merging a regression to such a core part of vortex

Comment on lines +10 to +12
pool, and limit buffer memory. `vortex-buffer` will own the allocator API and its memory. It will no
longer use `bytes::BytesMut` as its main storage type.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't?

@joseph-isaacs

Copy link
Copy Markdown
Contributor

I am still unsure how you would later want to limit allocations (due to memory usage) based on this API?

```rust
enum BufferBacking {
Owned(Allocation),
External(Box<dyn BufferOwner>),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does BufferOwner look like?

Comment thread rfcs/0065-buffer-allocation.md
@gatesn

gatesn commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

I am still unsure how you would later want to limit allocations (due to memory usage) based on this API?

I don't want to. At least not yet.

Unless you make every allocation fallible, by panicking or essentially turning it into async API, then you can't really apply back pressure.

This proposal lets us track memory more than limit it.

And engines will use this to spill or backpressure the actual big consumers like hash tables.

@AdamGS

AdamGS commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

going to do another deeper read later today, I want to see the PR and think about this more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants