mbutrovich commented on code in PR #12289:
URL: https://github.com/apache/arrow-rs/pull/12289#discussion_r4602912570
##########
arrow-row/src/variable.rs:
##########
@@ -217,6 +260,32 @@ fn encode_blocks<const SIZE: usize>(out: &mut [u8], val:
&[u8]) -> usize {
end_offset
}
+/// Copies `src` to the start of `dst`, which must be at least as long.
+///
+/// A value's last block is usually partial, and its length varies from row
+/// to row. `copy_from_slice` calls `memcpy` for a length the compiler can't
+/// see, and the call costs more than these few fixed-size copies. Each branch
+/// copies the first and the last bytes of `src`, which may overlap.
+#[inline]
+fn copy_short(dst: &mut [u8], src: &[u8]) {
Review Comment:
> Could you run `copy_short` without the other two changes on the
random-length cases?
For `Utf8`, `Binary`, string dictionaries, and lists, the table already
measures `copy_short` without the other two changes. The view loop only changes
`Utf8View` and `BinaryView`, and the strided path runs only when every column
is primitive or boolean
([lib.rs](https://github.com/apache/arrow-rs/blob/24c1ede738e7f52f3f90acaa2924d659a5373557/arrow-row/src/lib.rs#L1105-L1107)).
A separate run would build the same code for those cases.
Those rows show gains beyond fixed-length strings. Lists are 1.22x to 1.29x
and string dictionaries 1.03x to 1.15x. Random-length strings are 1.17x to
1.21x on the Xeon (`8192 string(1..40, 0)`) and 0.97x to 1.04x on Neoverse-V2,
counting `53 columns` from the other thread. Random-length `Utf8` of up to 100
bytes is too noisy to read: `4096 string(1..100, 0.5)` is 0.91x in the default
build and 1.49x in the aligned build on Neoverse-V2.
The gain doesn't come only from avoiding `memcpy`. Without the call,
`variable::encode_one` saves fewer callee-saved registers on every call. Its
prologue drops from four `stp` pairs to one on `aarch64-unknown-linux-gnu`, and
from seven pushes to five on `x86_64-unknown-linux-gnu`. Every string, binary,
view, list, and string dictionary value goes through `encode_one`, so leaving
`copy_short` out would give up the list, string, and dictionary gains above,
and possibly part of the view gains.
Should I keep it, and update the description to say it costs up to 3% on
Neoverse-V2 for random short strings?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]