Skip to content

Commit a93ebbe

Browse files
Dandandanalamb
authored andcommitted
ARROW-12390: [Rust] Inline from_trusted_len_iter, try_from_trusted_len_iter, extend_from_slice
This helps with further optimizing performance on quite some kernels: ``` length time: [721.26 ns 725.59 ns 731.42 ns] change: [-69.510% -69.125% -68.566%] (p = 0.00 < 0.05) Performance has improved. Found 11 outliers among 100 measurements (11.00%) 7 (7.00%) high mild 4 (4.00%) high severe take i32 512 time: [376.15 ns 378.51 ns 381.09 ns] change: [-18.681% -18.212% -17.542%] (p = 0.00 < 0.05) Performance has improved. Found 5 outliers among 100 measurements (5.00%) 3 (3.00%) high mild 2 (2.00%) high severe take i32 1024 time: [640.71 ns 641.87 ns 643.19 ns] change: [-28.880% -28.695% -28.516%] (p = 0.00 < 0.05) Performance has improved. Found 3 outliers among 100 measurements (3.00%) 2 (2.00%) high mild 1 (1.00%) high severe take i32 nulls 512 time: [634.80 ns 635.63 ns 636.56 ns] change: [-24.797% -23.403% -22.272%] (p = 0.00 < 0.05) Performance has improved. take i32 nulls 1024 time: [1.0084 us 1.0093 us 1.0103 us] change: [-44.482% -42.312% -40.209%] (p = 0.00 < 0.05) Performance has improved. Found 8 outliers among 100 measurements (8.00%) 1 (1.00%) low mild 5 (5.00%) high mild 2 (2.00%) high severe take bool 512 time: [1.4068 us 1.4188 us 1.4315 us] change: [-49.139% -48.684% -48.208%] (p = 0.00 < 0.05) Performance has improved. Found 2 outliers among 100 measurements (2.00%) 2 (2.00%) high mild take bool 1024 time: [2.6662 us 2.6807 us 2.6973 us] change: [-55.452% -55.133% -54.803%] (p = 0.00 < 0.05) Performance has improved. Found 1 outliers among 100 measurements (1.00%) 1 (1.00%) high mild take bool nulls 512 time: [1.3331 us 1.3452 us 1.3617 us] change: [-31.198% -30.327% -29.414%] (p = 0.00 < 0.05) Performance has improved. Found 3 outliers among 100 measurements (3.00%) 1 (1.00%) high mild 2 (2.00%) high severe take bool nulls 1024 time: [2.4789 us 2.4968 us 2.5229 us] change: [-40.358% -39.969% -39.558%] (p = 0.00 < 0.05) Performance has improved. Found 4 outliers among 100 measurements (4.00%) 3 (3.00%) high mild 1 (1.00%) high severe ``` FYI @jorgecarleitao Closes #10039 from Dandandan/inline_from_trusted_len_iter Authored-by: Heres, Daniel <[email protected]> Signed-off-by: Andrew Lamb <[email protected]>
1 parent 9e83b26 commit a93ebbe

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

rust/arrow/src/buffer/immutable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ impl Buffer {
275275
// 1. there is no trait `TrustedLen` in stable rust and therefore
276276
// we can't specialize `extend` for `TrustedLen` like `Vec` does.
277277
// 2. `from_trusted_len_iter` is faster.
278+
#[inline]
278279
pub unsafe fn from_trusted_len_iter<T: ArrowNativeType, I: Iterator<Item = T>>(
279280
iterator: I,
280281
) -> Self {
@@ -287,6 +288,7 @@ impl Buffer {
287288
/// # Safety
288289
/// This method assumes that the iterator's size is correct and is undefined behavior
289290
/// to use it on an iterator that reports an incorrect length.
291+
#[inline]
290292
pub unsafe fn try_from_trusted_len_iter<
291293
E,
292294
T: ArrowNativeType,

rust/arrow/src/buffer/mutable.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ impl MutableBuffer {
263263
/// buffer.extend_from_slice(&[2u32, 0]);
264264
/// assert_eq!(buffer.len(), 8) // u32 has 4 bytes
265265
/// ```
266+
#[inline]
266267
pub fn extend_from_slice<T: ToByteSlice>(&mut self, items: &[T]) {
267268
let len = items.len();
268269
let additional = len * std::mem::size_of::<T>();
@@ -391,6 +392,7 @@ impl MutableBuffer {
391392
// 1. there is no trait `TrustedLen` in stable rust and therefore
392393
// we can't specialize `extend` for `TrustedLen` like `Vec` does.
393394
// 2. `from_trusted_len_iter` is faster.
395+
#[inline]
394396
pub unsafe fn from_trusted_len_iter<T: ArrowNativeType, I: Iterator<Item = T>>(
395397
iterator: I,
396398
) -> Self {
@@ -432,6 +434,7 @@ impl MutableBuffer {
432434
// 1. there is no trait `TrustedLen` in stable rust and therefore
433435
// we can't specialize `extend` for `TrustedLen` like `Vec` does.
434436
// 2. `from_trusted_len_iter_bool` is faster.
437+
#[inline]
435438
pub unsafe fn from_trusted_len_iter_bool<I: Iterator<Item = bool>>(
436439
mut iterator: I,
437440
) -> Self {
@@ -476,6 +479,7 @@ impl MutableBuffer {
476479
/// # Safety
477480
/// This method assumes that the iterator's size is correct and is undefined behavior
478481
/// to use it on an iterator that reports an incorrect length.
482+
#[inline]
479483
pub unsafe fn try_from_trusted_len_iter<
480484
E,
481485
T: ArrowNativeType,

0 commit comments

Comments
 (0)