Share word-at-a-time primitives instead of optimizing each call site separately
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 12/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust
- Lĩnh vực
- data-engineering
Hướng nghiên cứu
This is a design proposal, not a starter task: the open question is whether arrow-buffer is the right home and whether parquet may take a required dependency on it. Read arrow-buffer/src/util/bit_util.rs, bit_chunk_iterator.rs and parquet/src/util/prefix.rs to see the existing primitives. Done means a maintainer settles the placement question; the first concrete step is a separate PR per primitive with benchmarks.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is your feature request related to a problem or challenge?
Many recent performance PRs make the same kind of change at one call site: process bytes or bits a word at a time instead of a byte at a time or through a libc call. Each PR tunes, tests, and benchmarks its own copy. This has three costs.
The tunings conflict. common_prefix_length in parquet (source, from #10549) compares 32-byte blocks inline because an out-of-line bcmp at 64 bytes measured slower. #12460 compares 8-byte chunks and hands values with a common length above 64 bytes to memcmp because memcmp measured faster there. Both run in the same file of the parquet arrow writer.
Gains don't reach the other copies. #11818 sped up UnalignedBitChunk::count_ones on aarch64. parquet has two count_set_bits functions of its own. The one in the arrow reader (source) calls UnalignedBitChunk::count_ones and got the gain. The one used to skip bit-packed definition levels (source) builds without the arrow feature, where arrow-buffer isn't available, so it has its own loop and didn't get the gain. compare_greater in the parquet column writer (source) still compares slices with a > b while #12460 speeds up the arrow writer's copy of the same comparison.
Work gets duplicated. #12024 and #12042 wrote the same multiply-based bool packing for BooleanBufferBuilder::append_slice at the same time. arrow-buffer has two identical read_u64 functions (bit_util.rs, bit_chunk_iterator.rs). byte_view_key in arrow-ord rank (source) and is_greater_bytes in #12460 (source) each build their own order-preserving integer key from a byte prefix.
Describe the solution you'd like
Give these primitives one home in arrow_buffer::util, next to bit_util and bit_chunk_iterator. Each primitive has one implementation, a test against a naive reference, and benchmark cases for both well-predicted and random input. Add a paragraph to the Performance Improvements section of CONTRIBUTING.md: before adding a word-at-a-time loop at a call site, check arrow_buffer::util and extend or add a primitive there. A PR that tunes a primitive shows results on both x86-64 and aarch64, because every caller inherits the tuning.
For byte comparison, the copies above share a structure with two parts that need different tuning. Most values that differ do so in their first word, so that word should be compared inline in the caller's loop. Values with a long shared prefix need a scan tuned for throughput, kept out of line so it doesn't bloat every caller. #12460 found both effects: inlining its chunk loop cost 2 to 4 points on random strings, and its out-of-line function had to stay a leaf to keep its gain. That suggests three functions:
prefix_key(s: &[u8]) -> u64returns the first 8 bytes as a big-endian integer, zero-padded whensis shorter.prefix_key(a) < prefix_key(b)impliesa < b. Equal keys say nothing. Au128variant covers 16-byte keys likebyte_view_key. Only theu128variant has a caller outsidecmp_bytesso far, so theu64one could stay private until it gets one.common_prefix_len(a: &[u8], b: &[u8]) -> usizeis the out-of-line scan. The choice between inline blocks andmemcmp, and its bound per target, gets made here once. TheDELTA_BYTE_ARRAYencoders, which inline today's scan, would make one call per value.cmp_bytes(a: &[u8], b: &[u8]) -> Orderingcompares the first 8 bytes inline when both values have that many. Shorter values and ties go to an out-of-line function that compares the prefix keys, then scans withcommon_prefix_lenand compares the byte at the mismatch or the lengths. Its result matchesa.cmp(b)for every input.
A prototype showed that this split has to be forced with attributes, because #[inline] alone doesn't hold across crates. With the default release profile, LLVM declined to inline a #[inline] cmp_bytes into parquet's ByteArrayEncoder::write_gather, which inlines the statistics loop of every array type, and kept 24 calls to an out-of-line copy. Marking all of cmp_bytes #[inline(always)] grew write_gather by 18%. Marking only the first-word comparison #[inline(always)], with the rest #[inline(never)], kept it at its current size. With every inlining decision set by an attribute, the split shouldn't depend on each consumer's LTO and codegen-unit settings, though I have checked it only without LTO. The out-of-line scan also lost its leaf status in the prototype to a bounds check whose panic path needed a stack frame. Details like these are easy to break at one call site, which is another reason to review them in one place.
For bitmaps, UnalignedBitChunk and BitChunks already exist. Once parquet can depend on the shared primitives without the arrow feature, it can keep one count_set_bits that calls UnalignedBitChunk::count_ones. arrow-buffer can keep one read_u64.
Each move would be its own PR with benchmark results.
Describe alternatives you've considered
Keeping the current approach costs nothing up front, and each PR stays small. The costs above grow with every new copy.
A generic chunked-scan abstraction, such as a const-generic block width with a closure per block, would cover more cases with one type. It would leave the inlining decisions above to each caller's instantiation, so each caller's generated code would need its own review, and it would be a larger public API to keep stable.
A new crate for these primitives would keep them out of arrow-buffer's API. It would be one more crate to version and release, and parquet would still need it without the arrow feature.
Each crate could keep pub(crate) copies and consolidate within the crate. That avoids new public API, but parquet, arrow-ord, and arrow-buffer would still tune separately.
Additional context
Anything shared between crates has to be pub, so each primitive becomes permanent API under the stability policy. That argues for a few concrete functions with results defined for every input.
parquet uses these primitives in code that builds without the arrow feature, where arrow-buffer is optional. arrow-buffer depends only on bytes, num-bigint, num-traits, and half (Cargo.toml), and parquet already depends on all four without the feature (Cargo.toml), so a required dependency would add no third-party crates.
Is arrow-buffer the right home, and is a required arrow-buffer dependency acceptable for parquet?
cc @alamb @Jefffrey @etseidl @Rich-T-kid @neilconway @adriangb @YUZHEthefool @viirya @waynexia @mightsleep @shanielh
- Ngôn ngữ chính
- Rust
- Star
- 3.7k
- Fork
- 1.5k
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 183
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/arrow-rs
-
parquet: `ArrowWriter::try_new` panics on a schema with a Union field instead of returning an errorĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`RunArray::try_new` rejects run ends whose null buffer has no nullsCó thể đã có người làm @Surajsuthar đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
apache/arrow-rs#12427 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Variant] `variant_get` string and binary cast errors show Rust builder type namesCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 61/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của apache/arrow-rs
Issue tương tự
-
area:ui effort:medium enhancement P7 source:agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
marketing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
machine rename accepts a label already used by another machine, making --machine <label> ambiguousĐang mởmaintainer-needed p2 remote triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug help wanted ui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
userFRM/egui-charts#4605 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày