Repository navigation
Commit d6b0bd7
authored
# Which issue does this PR close?
- Related to #10692.
# Rationale for this change
This change follows directly from the existing ByteView design history:
- #6408 traced slow ByteView slicing to allocating and cloning the
backing-buffer list. The discussion specifically identified `take` as
another operation that would benefit from sharing this list.
- #6427 distinguished two related but separate concerns: very large
buffer lists may indicate missing GC or deduplication, but avoiding
allocation when an operation retains the complete list is independently
worthwhile.
- #6808 demonstrated why eager deduplication in a general-purpose path
is a different tradeoff: it added substantial overhead to common
operations, and review favored treating ByteView compaction more
holistically.
- #9016 subsequently changed `GenericByteViewArray` to store the
collection as `Arc<[Buffer]>`, making it possible to share the complete
list without allocation.
The downstream impact is concrete.
[apache/datafusion#16206](apache/datafusion#16206)
describes hash joins where concatenating build-side batches produces
ByteView payload columns with many backing buffers, and constructing
join output repeatedly calls `take`. In that pattern, cloning and later
dropping every buffer handle can become a significant part of execution
time. Arrow issue #10692 provides a compact multi-stage `take` and
`BatchCoalescer` reproduction of the same ownership-metadata
amplification.
`take_byte_view` and `filter_byte_view` do not yet use this shared
representation. They rebuild the collection with
`data_buffers().to_vec()`, allocating a new collection and cloning every
`Buffer`. This makes the ownership bookkeeping for selection O(number of
backing buffers), despite retaining exactly the same complete buffer
list.
Selection already copies the chosen views while leaving their payloads
zero-copy. The cost of retaining the unchanged backing-buffer collection
should therefore not grow with the number of entries in that collection.
This PR completes that narrow part of the earlier design while leaving
buffer canonicalization as a separate problem.
# What changes are included in this PR?
- Change `GenericByteViewArray::data_buffers()` to return
`&Arc<[Buffer]>`, allowing callers to inspect the buffers as before or
clone the collection's `Arc` in O(1).
- Change `GenericByteViewArray::new_unchecked` to accept `Arc<[Buffer]>`
directly, making shared versus newly constructed buffer-list ownership
explicit at each call site.
- Use `Arc::clone` in the ByteView `take` and `filter` kernels instead
of rebuilding the collection.
- Replace three additional `data_buffers().to_vec()` call sites found by
the stricter constructor signature with shared `Arc` clones.
- Verify for both StringView and BinaryView that selection results share
the input buffer collection.
This PR only removes repeated ownership-metadata cloning. It retains the
same complete collection of backing buffers as before. It does not prune
or deduplicate buffer entries, remap views, run GC, or copy
string/binary payloads. The broader buffer-fragmentation problem
described in #10692 remains separate.
# Are these changes tested?
```shell
cargo fmt --all -- --check
cargo check --workspace --all-targets
cargo test -p arrow-array -p arrow-select -p arrow-row -p arrow-ipc
cargo test -p parquet --test arrow_reader invalid_utf8
cargo clippy -p arrow-array -p arrow-select -p arrow-row -p arrow-ipc -p parquet --all-targets --all-features -- -D warnings
cargo doc -p arrow-array --no-deps
```
A temporary local Criterion benchmark was used to validate the
asymptotic behavior. It takes 8,192 views distributed across a varying
number of buffer entries. The entries share one immutable payload
allocation, isolating collection-ownership cost from payload size.
`main` and this PR were built in separate Cargo target directories on an
Intel Xeon Platinum 8474C:
| Buffer entries | `main` | This PR | Speedup |
|---:|---:|---:|---:|
| 1 | 5.4900 us | 5.4619 us | 1.01x |
| 16 | 5.7342 us | 5.4577 us | 1.05x |
| 256 | 9.2806 us | 5.4518 us | 1.70x |
| 4,096 | 65.774 us | 5.4584 us | 12.05x |
Existing normal-size benchmarks did not regress:
| Benchmark | `main` | This PR |
|---|---:|---:|
| `take stringview 512` | 504.73 ns | 439.40 ns |
| `take stringview 1024` | 872.36 ns | 773.48 ns |
| `filter context mixed string view (kept 1/2)` | 73.406 us | 72.083 us
|
# Are there any user-facing changes?
There are two public signature changes. `data_buffers()` now returns
`&Arc<[Buffer]>` instead of `&[Buffer]`; slice methods remain available
through deref, while direct `for` iteration can use `.iter()`.
`new_unchecked` now requires `Arc<[Buffer]>`; callers constructing a
`Vec<Buffer>` can convert it with `.into()`. ByteView selection results
now share the immutable backing-buffer collection instead of allocating
an equivalent collection. Logical values, null handling, buffer indexes,
payload lifetimes, and GC behavior are unchanged.
# AI assistance
I used OpenAI Codex to help inspect the relevant implementation history,
draft the patch and tests, and prepare the benchmark harness and PR
text. I reviewed the implementation and benchmark methodology and ran
the checks above locally.
1 parent bab2817 commit d6b0bd7
11 files changed
Lines changed: 36 additions & 28 deletions
File tree
- arrow-array/src
- array
- builder
- arrow-ipc/src
- arrow-row/src
- arrow-select/src
- coalesce
- parquet
- src/arrow/buffer
- tests/arrow_reader
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
241 | | - | |
| 241 | + | |
242 | 242 | | |
243 | | - | |
| 243 | + | |
244 | 244 | | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
| 245 | + | |
249 | 246 | | |
250 | 247 | | |
251 | 248 | | |
| |||
254 | 251 | | |
255 | 252 | | |
256 | 253 | | |
257 | | - | |
| 254 | + | |
258 | 255 | | |
259 | 256 | | |
260 | 257 | | |
| |||
300 | 297 | | |
301 | 298 | | |
302 | 299 | | |
303 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
304 | 305 | | |
305 | | - | |
| 306 | + | |
306 | 307 | | |
307 | 308 | | |
308 | 309 | | |
| |||
543 | 544 | | |
544 | 545 | | |
545 | 546 | | |
546 | | - | |
| 547 | + | |
547 | 548 | | |
548 | 549 | | |
549 | 550 | | |
| |||
558 | 559 | | |
559 | 560 | | |
560 | 561 | | |
561 | | - | |
| 562 | + | |
562 | 563 | | |
563 | 564 | | |
564 | 565 | | |
| |||
657 | 658 | | |
658 | 659 | | |
659 | 660 | | |
660 | | - | |
| 661 | + | |
661 | 662 | | |
662 | 663 | | |
663 | 664 | | |
| |||
1635 | 1636 | | |
1636 | 1637 | | |
1637 | 1638 | | |
1638 | | - | |
| 1639 | + | |
1639 | 1640 | | |
1640 | 1641 | | |
1641 | 1642 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
503 | | - | |
| 503 | + | |
504 | 504 | | |
505 | 505 | | |
506 | 506 | | |
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
517 | | - | |
| 517 | + | |
518 | 518 | | |
519 | 519 | | |
520 | 520 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1815 | 1815 | | |
1816 | 1816 | | |
1817 | 1817 | | |
1818 | | - | |
| 1818 | + | |
1819 | 1819 | | |
1820 | 1820 | | |
1821 | 1821 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3604 | 3604 | | |
3605 | 3605 | | |
3606 | 3606 | | |
3607 | | - | |
| 3607 | + | |
3608 | 3608 | | |
3609 | 3609 | | |
3610 | 3610 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
378 | | - | |
| 378 | + | |
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
504 | | - | |
505 | | - | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
506 | 507 | | |
507 | 508 | | |
508 | 509 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
934 | 934 | | |
935 | 935 | | |
936 | 936 | | |
937 | | - | |
| 937 | + | |
938 | 938 | | |
939 | 939 | | |
940 | 940 | | |
| |||
1297 | 1297 | | |
1298 | 1298 | | |
1299 | 1299 | | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
1300 | 1303 | | |
1301 | 1304 | | |
1302 | 1305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
| 343 | + | |
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
633 | 633 | | |
634 | 634 | | |
635 | 635 | | |
| 636 | + | |
636 | 637 | | |
637 | | - | |
638 | | - | |
639 | | - | |
| 638 | + | |
640 | 639 | | |
641 | 640 | | |
642 | 641 | | |
| |||
1798 | 1797 | | |
1799 | 1798 | | |
1800 | 1799 | | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
1801 | 1803 | | |
1802 | 1804 | | |
1803 | 1805 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | | - | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
0 commit comments