Repository navigation
Commit 98dd977
authored
feat(buffer): add allocator-backed storage (#9668)
## Summary
Add allocator-backed storage to `vortex-buffer`.
Design: vortex-data/rfcs#65
## Changes
- Use `allocator_api2` for owned buffers.
- Keep external buffers zero-copy.
- Preserve runtime alignment and `bytes`/Arrow interop.
- Add allocator-aware constructors and tests.
## API Changes
Owned buffers no longer use `bytes::Bytes` as storage. The `bytes` crate
remains for interop.
`Buffer::into_inner` is now `Buffer::into_bytes`.
## Allocation benchmarks
Local medians on an Apple M5 Max with Rust 1.98.0:
```console
cargo bench -p vortex-buffer --bench allocation -- --max-time 2 --sample-count 500
```
| Operation | Size | Vortex | Vortex custom allocator | Bytes | Arrow |
| --- | ---: | ---: | ---: | ---: | ---: |
| allocate + drop | 1 KiB | 14.7 ns | 17.0 ns | 19.1 ns | 21.7 ns |
| allocate + drop | 16 KiB | 18.5 ns | 20.6 ns | 17.8 ns | 20.6 ns |
| allocate + drop | 64 KiB | 77.9 ns | 81.8 ns | 76.6 ns | 83.8 ns |
| allocate + freeze + drop | 64 B | 33.6 ns | 35.6 ns | 36.2 ns | 37.2
ns |
| allocate + freeze + drop | 256 B | 34.3 ns | 36.6 ns | 33.3 ns | 35.6
ns |
| take ownership of `Vec` + drop | 64 B | 22.9 ns | N/A | 7.7 ns | 20.6
ns |
| take ownership of `Vec` + drop | 1 KiB | 29.1 ns | N/A | 17.0 ns |
29.4 ns |
| take ownership of `Vec` + drop | 64 KiB | 56.1 ns | N/A | 38.8 ns |
46.0 ns |
The custom allocator's `Arc` adds about 2–4 ns per allocation lifecycle.
Normal mutable allocation
is comparable across the three implementations. Vortex and Arrow eagerly
allocate shared backing
metadata when taking ownership of a `Vec`; Bytes keeps a promotable Vec
representation and is
about 12–15 ns faster for small buffers.
The custom allocator column does not apply to `Vec` ownership. Rust's
`Vec` uses the global
allocator, so zero-copy adoption must retain that allocator for
deallocation. Moving its contents
to a custom allocator would require a copy and would measure a different
operation.
Vortex normally prefers 256-byte alignment. The checked-in suite also
measures Vortex with only
the requested alignment to separate alignment padding from ownership
overhead.
---------
Signed-off-by: Nicholas Gates <[email protected]>1 parent 6db45e9 commit 98dd977
21 files changed
Lines changed: 1481 additions & 488 deletions
File tree
- encodings
- pco/src
- sparse/src
- fuzz/fuzz_targets
- vortex-array/src
- arrays
- constant/vtable
- struct_/vtable
- builders
- vortex-arrow/src/executor
- vortex-buffer
- benches
- src
- bit
- vortex-datafusion/src/convert
- vortex-ipc/src/messages
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
| |||
568 | 567 | | |
569 | 568 | | |
570 | 569 | | |
571 | | - | |
| 570 | + | |
572 | 571 | | |
573 | 572 | | |
574 | | - | |
| 573 | + | |
575 | 574 | | |
576 | 575 | | |
577 | 576 | | |
578 | | - | |
| 577 | + | |
579 | 578 | | |
580 | 579 | | |
581 | | - | |
| 580 | + | |
582 | 581 | | |
583 | 582 | | |
584 | 583 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
| |||
217 | 216 | | |
218 | 217 | | |
219 | 218 | | |
220 | | - | |
| 219 | + | |
221 | 220 | | |
222 | 221 | | |
223 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
75 | | - | |
| 74 | + | |
76 | 75 | | |
77 | 76 | | |
78 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| |||
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
110 | | - | |
| 109 | + | |
111 | 110 | | |
112 | 111 | | |
113 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
20 | 21 | | |
21 | | - | |
22 | | - | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | | - | |
25 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | 33 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
800 | 800 | | |
801 | 801 | | |
802 | 802 | | |
803 | | - | |
| 803 | + | |
| 804 | + | |
804 | 805 | | |
805 | 806 | | |
806 | 807 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| |||
244 | 243 | | |
245 | 244 | | |
246 | 245 | | |
247 | | - | |
| 246 | + | |
248 | 247 | | |
249 | 248 | | |
250 | 249 | | |
251 | 250 | | |
252 | 251 | | |
253 | 252 | | |
254 | 253 | | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | 254 | | |
268 | 255 | | |
269 | 256 | | |
| |||
272 | 259 | | |
273 | 260 | | |
274 | 261 | | |
275 | | - | |
| 262 | + | |
276 | 263 | | |
277 | 264 | | |
278 | 265 | | |
279 | 266 | | |
280 | 267 | | |
281 | 268 | | |
282 | 269 | | |
283 | | - | |
284 | | - | |
285 | | - | |
| 270 | + | |
286 | 271 | | |
287 | 272 | | |
288 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
0 commit comments