You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "ctsk (via GitHub)" <gi...@apache.org> on 2025/06/25 13:44:30 UTC

[PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

ctsk opened a new pull request, #7773:
URL: https://github.com/apache/arrow-rs/pull/7773

   This PR is a continuation of the work by @ShiKaiWi  in https://github.com/apache/arrow-rs/pull/6427.
   
   # Which issue does this PR close?
   
   - Closes https://github.com/apache/arrow-rs/issues/6408.
   
   Please consult the description of https://github.com/apache/arrow-rs/pull/6427 for the details.
   
   # What changed since !6427
   
   - I've rebased the PR on the current main branch and fixed incompatibilities.
   - I added a `ViewBuffers` abstraction (analogous to `Fields` in `Schema`) that hides the internal representation (`Arc<[Buffer]>`) in the constructors of `GenericByteViewArray`.
   
   # Are there any user-facing changes?
   
   Yes, these are breaking changes.
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3005939597

   🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/gh_compare_arrow.sh) Running
   Linux aal-dev 6.11.0-1015-gcp #15~24.04.1-Ubuntu SMP Thu Apr 24 20:41:05 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
   Comparing arc-buffers (25e215a211007eb3d91938f2a4faf33af9d8656f) to 71ac9bd7146565ab47be8053c412b30c0a4c01c6 [diff](https://github.com/apache/arrow-rs/compare/71ac9bd7146565ab47be8053c412b30c0a4c01c6..25e215a211007eb3d91938f2a4faf33af9d8656f)
   BENCH_NAME=concatenate_kernel
   BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench concatenate_kernel 
   BENCH_FILTER=
   BENCH_BRANCH_NAME=arc-buffers
   Results will be posted here when complete
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3006362448

   I am not quite sure what to make of the benchmark results so far -- some of them may be noise -- we'll have to look into that further


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3005938635

   > In follow-up work, I want to expose the ViewBuffers representation to the kernels in arrow-select. The `take` kernel can then avoid allocating a new vector for the data buffers - I imagine other kernels will benefit aswell.
   
   Filter is another obvious candidate


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3005960297

   🤖: Benchmark completed
   
   <details><summary>Details</summary>
   <p>
   
   
   ```
   group                                                          arc-buffers                            main
   -----                                                          -----------                            ----
   concat 1024 arrays boolean 4                                   1.00     28.9±0.05µs        ? ?/sec    1.00     28.9±0.06µs        ? ?/sec
   concat 1024 arrays i32 4                                       1.00     15.5±0.06µs        ? ?/sec    1.00     15.4±0.08µs        ? ?/sec
   concat 1024 arrays str 4                                       1.00     56.3±0.19µs        ? ?/sec    1.01     56.6±0.36µs        ? ?/sec
   concat boolean 1024                                            1.00    429.5±3.86ns        ? ?/sec    1.00    428.9±0.41ns        ? ?/sec
   concat boolean 8192 over 100 arrays                            1.00     51.0±0.05µs        ? ?/sec    1.00     50.9±0.07µs        ? ?/sec
   concat boolean nulls 1024                                      1.00    750.2±3.69ns        ? ?/sec    1.05    784.7±4.93ns        ? ?/sec
   concat boolean nulls 8192 over 100 arrays                      1.00    110.0±0.27µs        ? ?/sec    1.00    109.7±0.22µs        ? ?/sec
   concat fixed size lists                                        1.10   728.7±20.71µs        ? ?/sec    1.00   660.7±14.51µs        ? ?/sec
   concat i32 1024                                                1.00    438.9±1.27ns        ? ?/sec    1.01    442.0±0.68ns        ? ?/sec
   concat i32 8192 over 100 arrays                                1.00    219.5±6.63µs        ? ?/sec    1.03    226.1±9.26µs        ? ?/sec
   concat i32 nulls 1024                                          1.00    753.8±1.72ns        ? ?/sec    1.00    754.3±0.80ns        ? ?/sec
   concat i32 nulls 8192 over 100 arrays                          1.00    282.4±9.13µs        ? ?/sec    1.06   298.3±13.07µs        ? ?/sec
   concat str 1024                                                1.00     13.3±0.94µs        ? ?/sec    1.01     13.5±1.03µs        ? ?/sec
   concat str 8192 over 100 arrays                                1.00    105.1±0.75ms        ? ?/sec    1.00    105.4±0.80ms        ? ?/sec
   concat str nulls 1024                                          1.05      7.2±0.83µs        ? ?/sec    1.00      6.8±0.86µs        ? ?/sec
   concat str nulls 8192 over 100 arrays                          1.00     51.9±0.51ms        ? ?/sec    1.00     52.0±0.59ms        ? ?/sec
   concat str_dict 1024                                           1.00      2.9±0.01µs        ? ?/sec    1.01      3.0±0.01µs        ? ?/sec
   concat str_dict_sparse 1024                                    1.00      6.9±0.03µs        ? ?/sec    1.00      6.9±0.02µs        ? ?/sec
   concat struct with int32 and dicts size=1024 count=2           1.00      6.7±0.07µs        ? ?/sec    1.03      7.0±0.15µs        ? ?/sec
   concat utf8_view  max_str_len=128 null_density=0               1.01     78.2±0.40µs        ? ?/sec    1.00     77.3±0.47µs        ? ?/sec
   concat utf8_view  max_str_len=128 null_density=0.2             1.01     84.3±0.45µs        ? ?/sec    1.00     83.5±0.29µs        ? ?/sec
   concat utf8_view  max_str_len=20 null_density=0                1.15     88.5±0.40µs        ? ?/sec    1.00     77.2±0.45µs        ? ?/sec
   concat utf8_view  max_str_len=20 null_density=0.2              1.13     95.1±0.28µs        ? ?/sec    1.00     83.9±0.52µs        ? ?/sec
   concat utf8_view all_inline max_str_len=12 null_density=0      1.18     47.4±3.25µs        ? ?/sec    1.00     40.1±3.28µs        ? ?/sec
   concat utf8_view all_inline max_str_len=12 null_density=0.2    1.17     56.3±3.89µs        ? ?/sec    1.00     48.2±3.63µs        ? ?/sec
   ```
   
   
   </p>
   </details>
   
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2173187524


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -736,12 +745,18 @@ where
 }
 
 impl<T: ByteViewType + ?Sized> From<GenericByteViewArray<T>> for ArrayData {
-    fn from(mut array: GenericByteViewArray<T>) -> Self {
+    fn from(array: GenericByteViewArray<T>) -> Self {
         let len = array.len();
-        array.buffers.insert(0, array.views.into_inner());
+        let new_buffers = {

Review Comment:
   I can reproduce the slowdown for the concat kernel on my laptop.
   
   For this allocation, I believe we in turn save doing this allocation during `clone()` when using `Arc<ViewBuffers>`...



##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -736,12 +745,18 @@ where
 }
 
 impl<T: ByteViewType + ?Sized> From<GenericByteViewArray<T>> for ArrayData {
-    fn from(mut array: GenericByteViewArray<T>) -> Self {
+    fn from(array: GenericByteViewArray<T>) -> Self {
         let len = array.len();
-        array.buffers.insert(0, array.views.into_inner());
+        let new_buffers = {

Review Comment:
   Nevermind, it appears that I can't consistently reproduce the slowdown.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3006002448

   🤖: Benchmark completed
   
   <details><summary>Details</summary>
   <p>
   
   
   ```
   group                                                                                arc-buffers                            main
   -----                                                                                -----------                            ----
   filter: mixed_dict, 8192, nulls: 0, selectivity: 0.001                               1.00    298.5±2.67ms        ? ?/sec    1.00    297.6±2.19ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0, selectivity: 0.01                                1.02      9.3±0.10ms        ? ?/sec    1.00      9.1±0.11ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0, selectivity: 0.1                                 1.00      4.3±0.11ms        ? ?/sec    1.03      4.4±0.11ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0, selectivity: 0.8                                 1.00      3.5±0.02ms        ? ?/sec    1.01      3.5±0.02ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0.1, selectivity: 0.001                             1.00    290.8±2.00ms        ? ?/sec    1.02    296.9±2.65ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0.1, selectivity: 0.01                              1.01     10.7±0.12ms        ? ?/sec    1.00     10.7±0.09ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0.1, selectivity: 0.1                               1.00      4.7±0.12ms        ? ?/sec    1.01      4.8±0.12ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0.1, selectivity: 0.8                               1.00      4.5±0.02ms        ? ?/sec    1.04      4.7±0.02ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0, selectivity: 0.001                               1.03     74.3±0.50ms        ? ?/sec    1.00     72.4±0.50ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0, selectivity: 0.01                                1.02     13.0±0.14ms        ? ?/sec    1.00     12.7±0.12ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0, selectivity: 0.1                                 1.00     10.2±0.32ms        ? ?/sec    1.00     10.2±0.35ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0, selectivity: 0.8                                 1.00      8.0±0.13ms        ? ?/sec    1.04      8.3±0.20ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0.1, selectivity: 0.001                             1.02     97.6±0.51ms        ? ?/sec    1.00     95.3±0.59ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0.1, selectivity: 0.01                              1.02     15.3±0.14ms        ? ?/sec    1.00     15.0±0.13ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0.1, selectivity: 0.1                               1.00     10.2±0.36ms        ? ?/sec    1.01     10.3±0.40ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0.1, selectivity: 0.8                               1.00      9.5±0.16ms        ? ?/sec    1.06     10.0±0.22ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0, selectivity: 0.001      1.04     60.1±0.20ms        ? ?/sec    1.00     57.6±0.22ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0, selectivity: 0.01       1.03      7.7±0.03ms        ? ?/sec    1.00      7.5±0.03ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0, selectivity: 0.1        1.01      5.0±0.24ms        ? ?/sec    1.00      4.9±0.21ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0, selectivity: 0.8        1.02      3.1±0.03ms        ? ?/sec    1.00      3.1±0.05ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0.1, selectivity: 0.001    1.02     80.2±0.28ms        ? ?/sec    1.00     78.3±0.33ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0.1, selectivity: 0.01     1.04     11.0±0.05ms        ? ?/sec    1.00     10.6±0.05ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0.1, selectivity: 0.1      1.00      5.8±0.22ms        ? ?/sec    1.01      5.8±0.24ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0.1, selectivity: 0.8      1.00      3.7±0.01ms        ? ?/sec    1.08      3.9±0.02ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0, selectivity: 0.001       1.05     53.6±0.13ms        ? ?/sec    1.00     50.8±0.16ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0, selectivity: 0.01        1.02      6.3±0.03ms        ? ?/sec    1.00      6.1±0.03ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0, selectivity: 0.1         1.03      2.8±0.21ms        ? ?/sec    1.00      2.8±0.15ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0, selectivity: 0.8         1.01      2.3±0.01ms        ? ?/sec    1.00      2.2±0.02ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0.1, selectivity: 0.001     1.09     76.4±0.25ms        ? ?/sec    1.00     69.8±0.27ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0.1, selectivity: 0.01      1.05      9.8±0.03ms        ? ?/sec    1.00      9.3±0.03ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0.1, selectivity: 0.1       1.00      3.7±0.17ms        ? ?/sec    1.04      3.8±0.22ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0.1, selectivity: 0.8       1.00      4.5±0.02ms        ? ?/sec    1.02      4.6±0.02ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0, selectivity: 0.001                          1.11     68.2±0.14ms        ? ?/sec    1.00     61.7±0.16ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0, selectivity: 0.01                           1.09      8.3±0.06ms        ? ?/sec    1.00      7.7±0.04ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0, selectivity: 0.1                            1.00      4.7±0.24ms        ? ?/sec    1.01      4.7±0.22ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0, selectivity: 0.8                            1.01      3.6±0.02ms        ? ?/sec    1.00      3.6±0.02ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0.1, selectivity: 0.001                        1.15     92.0±0.28ms        ? ?/sec    1.00     79.7±0.26ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0.1, selectivity: 0.01                         1.10     12.3±0.03ms        ? ?/sec    1.00     11.2±0.03ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0.1, selectivity: 0.1                          1.01      6.4±0.24ms        ? ?/sec    1.00      6.4±0.26ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0.1, selectivity: 0.8                          1.03      6.3±0.02ms        ? ?/sec    1.00      6.1±0.02ms        ? ?/sec
   ```
   
   
   </p>
   </details>
   
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3006002568

   🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/gh_compare_arrow.sh) Running
   Linux aal-dev 6.11.0-1015-gcp #15~24.04.1-Ubuntu SMP Thu Apr 24 20:41:05 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
   Comparing arc-buffers (25e215a211007eb3d91938f2a4faf33af9d8656f) to 71ac9bd7146565ab47be8053c412b30c0a4c01c6 [diff](https://github.com/apache/arrow-rs/compare/71ac9bd7146565ab47be8053c412b30c0a4c01c6..25e215a211007eb3d91938f2a4faf33af9d8656f)
   BENCH_NAME=filter_kernels
   BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench filter_kernels 
   BENCH_FILTER=
   BENCH_BRANCH_NAME=arc-buffers
   Results will be posted here when complete
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2167647225


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -734,12 +743,20 @@ where
 }
 
 impl<T: ByteViewType + ?Sized> From<GenericByteViewArray<T>> for ArrayData {
-    fn from(mut array: GenericByteViewArray<T>) -> Self {
+    fn from(array: GenericByteViewArray<T>) -> Self {
         let len = array.len();
-        array.buffers.insert(0, array.views.into_inner());
+        let new_buffers = {
+            let mut buffers = Vec::with_capacity(array.buffers.len() + 1);
+            buffers.push(array.views.into_inner());
+            for buffer in array.buffers.iter() {
+                buffers.push(buffer.clone());
+            }

Review Comment:
   This worked when the internal representation was a Vec<Buffer>, but doesn't work anymore when we switch to Arc<[Buffer]> -- other batches might hold a reference to this buffer array now too.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3084197279

   🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/gh_compare_arrow.sh) Running
   Linux aal-dev 6.11.0-1016-gcp #16~24.04.1-Ubuntu SMP Wed May 28 02:40:52 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
   Comparing arc-buffers (e71a332eba27c8c4b761005fe5d16022773b3bfa) to e42df82a6d1e52f0dbdfa87130c2974ce460af69 [diff](https://github.com/apache/arrow-rs/compare/e42df82a6d1e52f0dbdfa87130c2974ce460af69..e71a332eba27c8c4b761005fe5d16022773b3bfa)
   BENCH_NAME=concatenate_kernel
   BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench concatenate_kernel 
   BENCH_FILTER=
   BENCH_BRANCH_NAME=arc-buffers
   Results will be posted here when complete
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3676432200

   There is a new (less invasive) proposal from @maxburke here:
   - https://github.com/apache/arrow-rs/pull/9016


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3078549150

   I've added a commit that excludes the `drop` time from the concat benchmark (by using `iter_with_large_drop`). Can you trigger it again @alamb? Unfortunately I can't reproduce that regression locally.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3084289804

   🤖: Benchmark completed
   
   <details><summary>Details</summary>
   <p>
   
   
   ```
   group                                                                                arc-buffers                            main
   -----                                                                                -----------                            ----
   filter: mixed_dict, 8192, nulls: 0, selectivity: 0.001                               1.00    255.8±1.83ms        ? ?/sec    1.00    255.1±1.45ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0, selectivity: 0.01                                1.00      8.8±0.09ms        ? ?/sec    1.01      8.9±0.05ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0, selectivity: 0.1                                 1.00      4.2±0.10ms        ? ?/sec    1.03      4.4±0.11ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0, selectivity: 0.8                                 1.00      3.5±0.03ms        ? ?/sec    1.00      3.5±0.01ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0.1, selectivity: 0.001                             1.00    244.8±1.56ms        ? ?/sec    1.00    244.6±1.90ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0.1, selectivity: 0.01                              1.02     10.3±0.07ms        ? ?/sec    1.00     10.1±0.06ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0.1, selectivity: 0.1                               1.03      4.7±0.06ms        ? ?/sec    1.00      4.6±0.02ms        ? ?/sec
   filter: mixed_dict, 8192, nulls: 0.1, selectivity: 0.8                               1.00      4.7±0.04ms        ? ?/sec    1.01      4.7±0.03ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0, selectivity: 0.001                               1.00     58.5±0.93ms        ? ?/sec    1.00     58.4±0.35ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0, selectivity: 0.01                                1.02     12.1±0.20ms        ? ?/sec    1.00     11.9±0.15ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0, selectivity: 0.1                                 1.00      9.7±0.21ms        ? ?/sec    1.04     10.1±0.29ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0, selectivity: 0.8                                 1.23     10.4±0.23ms        ? ?/sec    1.00      8.4±0.17ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0.1, selectivity: 0.001                             1.00     80.0±0.85ms        ? ?/sec    1.00     79.7±0.65ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0.1, selectivity: 0.01                              1.02     13.8±0.15ms        ? ?/sec    1.00     13.6±0.09ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0.1, selectivity: 0.1                               1.02     10.4±0.34ms        ? ?/sec    1.00     10.1±0.31ms        ? ?/sec
   filter: mixed_utf8, 8192, nulls: 0.1, selectivity: 0.8                               1.00      9.7±0.11ms        ? ?/sec    1.04     10.1±0.17ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0, selectivity: 0.001      1.00     48.6±0.13ms        ? ?/sec    1.00     48.4±0.23ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0, selectivity: 0.01       1.00      6.2±0.02ms        ? ?/sec    1.01      6.2±0.03ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0, selectivity: 0.1        1.02      4.9±0.26ms        ? ?/sec    1.00      4.8±0.10ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0, selectivity: 0.8        1.00      3.0±0.03ms        ? ?/sec    1.06      3.2±0.03ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0.1, selectivity: 0.001    1.00     62.5±0.15ms        ? ?/sec    1.00     62.7±0.21ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0.1, selectivity: 0.01     1.01      8.6±0.04ms        ? ?/sec    1.00      8.5±0.03ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0.1, selectivity: 0.1      1.07      5.8±0.23ms        ? ?/sec    1.00      5.4±0.15ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=128), 8192, nulls: 0.1, selectivity: 0.8      1.00      3.7±0.01ms        ? ?/sec    1.05      3.9±0.01ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0, selectivity: 0.001       1.00     42.1±0.10ms        ? ?/sec    1.00     42.3±0.08ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0, selectivity: 0.01        1.00      4.8±0.02ms        ? ?/sec    1.02      4.9±0.01ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0, selectivity: 0.1         1.00      2.6±0.16ms        ? ?/sec    1.00      2.6±0.15ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0, selectivity: 0.8         1.00      2.2±0.01ms        ? ?/sec    1.10      2.4±0.01ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0.1, selectivity: 0.001     1.00     51.6±0.11ms        ? ?/sec    1.08     55.6±0.12ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0.1, selectivity: 0.01      1.00      7.0±0.03ms        ? ?/sec    1.05      7.4±0.02ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0.1, selectivity: 0.1       1.04      3.8±0.13ms        ? ?/sec    1.00      3.6±0.21ms        ? ?/sec
   filter: mixed_utf8view (max_string_len=20), 8192, nulls: 0.1, selectivity: 0.8       1.00      4.5±0.01ms        ? ?/sec    1.06      4.8±0.02ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0, selectivity: 0.001                          1.03     67.0±0.45ms        ? ?/sec    1.00     64.8±0.09ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0, selectivity: 0.01                           1.00      8.0±0.04ms        ? ?/sec    1.03      8.3±0.02ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0, selectivity: 0.1                            1.00      4.6±0.11ms        ? ?/sec    1.02      4.7±0.15ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0, selectivity: 0.8                            1.00      3.3±0.01ms        ? ?/sec    1.20      4.0±0.02ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0.1, selectivity: 0.001                        1.03     91.3±0.46ms        ? ?/sec    1.00     88.9±0.14ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0.1, selectivity: 0.01                         1.00     11.8±0.05ms        ? ?/sec    1.05     12.4±0.02ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0.1, selectivity: 0.1                          1.00      6.2±0.05ms        ? ?/sec    1.06      6.6±0.10ms        ? ?/sec
   filter: single_utf8view, 8192, nulls: 0.1, selectivity: 0.8                          1.00      6.1±0.02ms        ? ?/sec    1.04      6.3±0.03ms        ? ?/sec
   ```
   
   
   </p>
   </details>
   
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2173174118


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -609,8 +617,9 @@ impl<T: ByteViewType + ?Sized> Array for GenericByteViewArray<T> {
 
     fn shrink_to_fit(&mut self) {
         self.views.shrink_to_fit();
-        self.buffers.iter_mut().for_each(|b| b.shrink_to_fit());
-        self.buffers.shrink_to_fit();
+        if let Some(buffers) = Arc::get_mut(&mut self.buffers.0) {

Review Comment:
   The underlying Buffers are reference counted too, and only shrink themselves if the reference count is 0. So while this does change the semantics slightly, I don't think it changes as much in practice: When the Arc is shared, the (current) alternative would be to store references to the same buffers in another Vec - thus incrementing the reference counts on the underlying buffers and making their `shrink_to_fit` a no-op.
   
   That's also why `make_mut` wont lead to more shrinking



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3004864561

   In follow-up work, I want to expose the ViewBuffers representation to the kernels. The `take` kernel can then avoid allocating a new vector for the data buffers - I imagine other kernels will benefit aswell.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2173687750


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -736,12 +745,18 @@ where
 }
 
 impl<T: ByteViewType + ?Sized> From<GenericByteViewArray<T>> for ArrayData {
-    fn from(mut array: GenericByteViewArray<T>) -> Self {
+    fn from(array: GenericByteViewArray<T>) -> Self {
         let len = array.len();
-        array.buffers.insert(0, array.views.into_inner());
+        let new_buffers = {

Review Comment:
   yeah it is really strange



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3676490617

   That proposal is basically identical to the original PR #7773, where it was requested that the API shouldn't expose Arc<[Buffer]>, hence motivating PR.
   
   Regardless, I'm glad there's progress on this (seamingly simple) change


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3006062783

   🤖: Benchmark completed
   
   <details><summary>Details</summary>
   <p>
   
   
   ```
   group                                                                         arc-buffers                            main
   -----                                                                         -----------                            ----
   filter context decimal128 (kept 1/2)                                          1.10     46.7±8.16µs        ? ?/sec    1.00     42.4±4.58µs        ? ?/sec
   filter context decimal128 high selectivity (kept 1023/1024)                   1.00     49.7±1.70µs        ? ?/sec    1.00     49.9±1.54µs        ? ?/sec
   filter context decimal128 low selectivity (kept 1/1024)                       1.06    258.8±1.50ns        ? ?/sec    1.00    245.2±0.34ns        ? ?/sec
   filter context f32 (kept 1/2)                                                 1.00     62.3±0.15µs        ? ?/sec    1.58     98.3±0.27µs        ? ?/sec
   filter context f32 high selectivity (kept 1023/1024)                          1.00     13.4±0.39µs        ? ?/sec    1.00     13.4±0.35µs        ? ?/sec
   filter context f32 low selectivity (kept 1/1024)                              1.00    436.2±0.88ns        ? ?/sec    1.34    584.0±1.04ns        ? ?/sec
   filter context fsb with value length 20 (kept 1/2)                            1.00     42.5±0.13µs        ? ?/sec    1.67     71.1±0.12µs        ? ?/sec
   filter context fsb with value length 20 high selectivity (kept 1023/1024)     1.00     42.5±0.16µs        ? ?/sec    1.67     70.9±0.11µs        ? ?/sec
   filter context fsb with value length 20 low selectivity (kept 1/1024)         1.00     42.4±0.12µs        ? ?/sec    1.67     70.9±0.12µs        ? ?/sec
   filter context fsb with value length 5 (kept 1/2)                             1.00     42.4±0.08µs        ? ?/sec    1.67     70.9±0.12µs        ? ?/sec
   filter context fsb with value length 5 high selectivity (kept 1023/1024)      1.00     42.4±0.14µs        ? ?/sec    1.67     71.0±0.19µs        ? ?/sec
   filter context fsb with value length 5 low selectivity (kept 1/1024)          1.00     42.4±0.09µs        ? ?/sec    1.67     71.0±0.13µs        ? ?/sec
   filter context fsb with value length 50 (kept 1/2)                            1.00     42.5±0.10µs        ? ?/sec    1.67     70.9±0.10µs        ? ?/sec
   filter context fsb with value length 50 high selectivity (kept 1023/1024)     1.00     42.4±0.06µs        ? ?/sec    1.67     70.9±0.24µs        ? ?/sec
   filter context fsb with value length 50 low selectivity (kept 1/1024)         1.00     42.5±0.15µs        ? ?/sec    1.67     70.9±0.10µs        ? ?/sec
   filter context i32 (kept 1/2)                                                 1.00     22.6±0.09µs        ? ?/sec    1.01     22.8±0.09µs        ? ?/sec
   filter context i32 high selectivity (kept 1023/1024)                          1.00      6.3±0.38µs        ? ?/sec    1.03      6.5±0.30µs        ? ?/sec
   filter context i32 low selectivity (kept 1/1024)                              1.00    248.9±0.69ns        ? ?/sec    1.00    247.9±0.20ns        ? ?/sec
   filter context i32 w NULLs (kept 1/2)                                         1.00     65.7±0.40µs        ? ?/sec    1.44     94.4±0.34µs        ? ?/sec
   filter context i32 w NULLs high selectivity (kept 1023/1024)                  1.05     13.6±0.64µs        ? ?/sec    1.00     13.0±0.37µs        ? ?/sec
   filter context i32 w NULLs low selectivity (kept 1/1024)                      1.00    435.7±0.85ns        ? ?/sec    1.09    474.6±0.93ns        ? ?/sec
   filter context mixed string view (kept 1/2)                                   1.00     97.4±1.80µs        ? ?/sec    1.25    122.0±7.68µs        ? ?/sec
   filter context mixed string view high selectivity (kept 1023/1024)            1.01     58.7±1.06µs        ? ?/sec    1.00     58.4±1.32µs        ? ?/sec
   filter context mixed string view low selectivity (kept 1/1024)                1.00    676.7±0.89ns        ? ?/sec    1.01    683.1±1.13ns        ? ?/sec
   filter context short string view (kept 1/2)                                   1.00     96.9±1.51µs        ? ?/sec    1.17    113.5±4.38µs        ? ?/sec
   filter context short string view high selectivity (kept 1023/1024)            1.04     59.4±0.68µs        ? ?/sec    1.00     57.4±1.59µs        ? ?/sec
   filter context short string view low selectivity (kept 1/1024)                1.00    486.4±0.89ns        ? ?/sec    1.01    490.2±0.89ns        ? ?/sec
   filter context string (kept 1/2)                                              1.00   560.3±11.64µs        ? ?/sec    1.08   605.7±14.43µs        ? ?/sec
   filter context string dictionary (kept 1/2)                                   1.00     23.4±0.08µs        ? ?/sec    1.01     23.5±0.11µs        ? ?/sec
   filter context string dictionary high selectivity (kept 1023/1024)            1.00      6.9±0.33µs        ? ?/sec    1.11      7.6±0.31µs        ? ?/sec
   filter context string dictionary low selectivity (kept 1/1024)                1.00    808.3±1.27ns        ? ?/sec    1.05    848.2±1.88ns        ? ?/sec
   filter context string dictionary w NULLs (kept 1/2)                           1.00     66.6±0.27µs        ? ?/sec    1.43     95.3±0.19µs        ? ?/sec
   filter context string dictionary w NULLs high selectivity (kept 1023/1024)    1.07     15.0±0.57µs        ? ?/sec    1.00     14.0±0.30µs        ? ?/sec
   filter context string dictionary w NULLs low selectivity (kept 1/1024)        1.00   1033.5±1.73ns        ? ?/sec    1.05   1084.0±3.32ns        ? ?/sec
   filter context string high selectivity (kept 1023/1024)                       1.00   676.5±14.39µs        ? ?/sec    1.02   687.1±39.83µs        ? ?/sec
   filter context string low selectivity (kept 1/1024)                           1.03   1141.7±3.87ns        ? ?/sec    1.00   1104.6±1.93ns        ? ?/sec
   filter context u8 (kept 1/2)                                                  1.00     18.8±0.04µs        ? ?/sec    1.00     18.9±0.09µs        ? ?/sec
   filter context u8 high selectivity (kept 1023/1024)                           1.00   1827.5±8.74ns        ? ?/sec    1.14      2.1±0.01µs        ? ?/sec
   filter context u8 low selectivity (kept 1/1024)                               1.00    239.7±0.45ns        ? ?/sec    1.01    241.1±0.40ns        ? ?/sec
   filter context u8 w NULLs (kept 1/2)                                          1.00     61.8±0.16µs        ? ?/sec    1.46     90.2±0.16µs        ? ?/sec
   filter context u8 w NULLs high selectivity (kept 1023/1024)                   1.06      8.6±0.03µs        ? ?/sec    1.00      8.1±0.03µs        ? ?/sec
   filter context u8 w NULLs low selectivity (kept 1/1024)                       1.00    536.1±0.98ns        ? ?/sec    1.05    564.4±1.02ns        ? ?/sec
   filter decimal128 (kept 1/2)                                                  1.00     95.7±0.42µs        ? ?/sec    1.02     97.5±0.56µs        ? ?/sec
   filter decimal128 high selectivity (kept 1023/1024)                           1.00     52.2±1.79µs        ? ?/sec    1.02     53.2±1.58µs        ? ?/sec
   filter decimal128 low selectivity (kept 1/1024)                               1.25      3.0±0.01µs        ? ?/sec    1.00      2.4±0.01µs        ? ?/sec
   filter f32 (kept 1/2)                                                         1.17    228.7±0.48µs        ? ?/sec    1.00    196.2±0.51µs        ? ?/sec
   filter fsb with value length 20 (kept 1/2)                                    1.00    133.6±0.41µs        ? ?/sec    1.13    151.3±0.42µs        ? ?/sec
   filter fsb with value length 20 high selectivity (kept 1023/1024)             1.00     71.4±1.58µs        ? ?/sec    1.00     71.1±1.70µs        ? ?/sec
   filter fsb with value length 20 low selectivity (kept 1/1024)                 1.20      3.2±0.02µs        ? ?/sec    1.00      2.6±0.01µs        ? ?/sec
   filter fsb with value length 5 (kept 1/2)                                     1.00    131.5±0.20µs        ? ?/sec    1.16    152.8±0.25µs        ? ?/sec
   filter fsb with value length 5 high selectivity (kept 1023/1024)              1.00     10.9±0.67µs        ? ?/sec    1.04     11.3±0.66µs        ? ?/sec
   filter fsb with value length 5 low selectivity (kept 1/1024)                  1.26      3.1±0.00µs        ? ?/sec    1.00      2.5±0.01µs        ? ?/sec
   filter fsb with value length 50 (kept 1/2)                                    1.01    196.0±7.63µs        ? ?/sec    1.00    194.6±8.56µs        ? ?/sec
   filter fsb with value length 50 high selectivity (kept 1023/1024)             1.00    206.0±9.89µs        ? ?/sec    1.07    219.9±8.09µs        ? ?/sec
   filter fsb with value length 50 low selectivity (kept 1/1024)                 1.20      3.1±0.01µs        ? ?/sec    1.00      2.6±0.01µs        ? ?/sec
   filter i32 (kept 1/2)                                                         1.03     94.3±0.17µs        ? ?/sec    1.00     91.6±0.22µs        ? ?/sec
   filter i32 high selectivity (kept 1023/1024)                                  1.00      8.6±0.42µs        ? ?/sec    1.06      9.1±0.38µs        ? ?/sec
   filter i32 low selectivity (kept 1/1024)                                      1.26      3.1±0.01µs        ? ?/sec    1.00      2.5±0.00µs        ? ?/sec
   filter optimize (kept 1/2)                                                    1.04     85.8±0.15µs        ? ?/sec    1.00     82.6±0.34µs        ? ?/sec
   filter optimize high selectivity (kept 1023/1024)                             1.00      2.7±0.01µs        ? ?/sec    1.17      3.1±0.01µs        ? ?/sec
   filter optimize low selectivity (kept 1/1024)                                 1.36      2.9±0.00µs        ? ?/sec    1.00      2.1±0.01µs        ? ?/sec
   filter run array (kept 1/2)                                                   1.00    428.5±1.23µs        ? ?/sec    1.09    468.9±0.75µs        ? ?/sec
   filter run array high selectivity (kept 1023/1024)                            1.00    379.5±1.14µs        ? ?/sec    1.18    448.8±0.97µs        ? ?/sec
   filter run array low selectivity (kept 1/1024)                                1.00    314.7±0.77µs        ? ?/sec    1.06    332.5±1.27µs        ? ?/sec
   filter single record batch                                                    1.00     91.3±0.20µs        ? ?/sec    1.00     91.6±0.11µs        ? ?/sec
   filter u8 (kept 1/2)                                                          1.00     91.9±0.20µs        ? ?/sec    1.04     95.4±0.15µs        ? ?/sec
   filter u8 high selectivity (kept 1023/1024)                                   1.00      3.8±0.04µs        ? ?/sec    1.08      4.1±0.01µs        ? ?/sec
   filter u8 low selectivity (kept 1/1024)                                       1.24      3.1±0.01µs        ? ?/sec    1.00      2.5±0.01µs        ? ?/sec
   ```
   
   
   </p>
   </details>
   
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2167618926


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -162,7 +164,7 @@ use super::ByteArrayType;
 pub struct GenericByteViewArray<T: ByteViewType + ?Sized> {
     data_type: DataType,
     views: ScalarBuffer<u128>,
-    buffers: Vec<Buffer>,
+    buffers: Arc<[Buffer]>,

Review Comment:
   Should be possible.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2167701896


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -734,12 +743,20 @@ where
 }
 
 impl<T: ByteViewType + ?Sized> From<GenericByteViewArray<T>> for ArrayData {
-    fn from(mut array: GenericByteViewArray<T>) -> Self {
+    fn from(array: GenericByteViewArray<T>) -> Self {
         let len = array.len();
-        array.buffers.insert(0, array.views.into_inner());
+        let new_buffers = {
+            let mut buffers = Vec::with_capacity(array.buffers.len() + 1);
+            buffers.push(array.views.into_inner());
+            for buffer in array.buffers.iter() {
+                buffers.push(buffer.clone());
+            }

Review Comment:
   How about
   ```rust
    buffers.extend(array.buffers.iter().cloned())
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3084229134

   🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/gh_compare_arrow.sh) Running
   Linux aal-dev 6.11.0-1016-gcp #16~24.04.1-Ubuntu SMP Wed May 28 02:40:52 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
   Comparing arc-buffers (e71a332eba27c8c4b761005fe5d16022773b3bfa) to e42df82a6d1e52f0dbdfa87130c2974ce460af69 [diff](https://github.com/apache/arrow-rs/compare/e42df82a6d1e52f0dbdfa87130c2974ce460af69..e71a332eba27c8c4b761005fe5d16022773b3bfa)
   BENCH_NAME=coalesce_kernels
   BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench coalesce_kernels 
   BENCH_FILTER=
   BENCH_BRANCH_NAME=arc-buffers
   Results will be posted here when complete
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3084197000

   🤖: Benchmark completed
   
   <details><summary>Details</summary>
   <p>
   
   
   ```
   group                       arc-buffers                            main
   -----                       -----------                            ----
   gc view types all           1.00    824.8±3.02µs        ? ?/sec    1.00    826.2±3.16µs        ? ?/sec
   gc view types slice half    1.00    409.2±0.89µs        ? ?/sec    1.00    408.9±0.84µs        ? ?/sec
   view types slice            1.00    636.7±0.99ns        ? ?/sec    1.11    704.3±1.14ns        ? ?/sec
   ```
   
   
   </p>
   </details>
   
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3084373016

   🤖: Benchmark completed
   
   <details><summary>Details</summary>
   <p>
   
   
   ```
   group                                                                         arc-buffers                            main
   -----                                                                         -----------                            ----
   filter context decimal128 (kept 1/2)                                          1.00     41.9±5.60µs        ? ?/sec    1.07     44.9±7.38µs        ? ?/sec
   filter context decimal128 high selectivity (kept 1023/1024)                   1.00     51.4±1.32µs        ? ?/sec    1.00     51.5±1.36µs        ? ?/sec
   filter context decimal128 low selectivity (kept 1/1024)                       1.00    225.8±0.23ns        ? ?/sec    1.14    257.9±0.40ns        ? ?/sec
   filter context f32 (kept 1/2)                                                 1.60     97.7±0.16µs        ? ?/sec    1.00     60.9±0.14µs        ? ?/sec
   filter context f32 high selectivity (kept 1023/1024)                          1.00     13.3±0.47µs        ? ?/sec    1.02     13.6±0.46µs        ? ?/sec
   filter context f32 low selectivity (kept 1/1024)                              1.08    482.6±0.36ns        ? ?/sec    1.00    445.2±0.56ns        ? ?/sec
   filter context fsb with value length 20 (kept 1/2)                            1.67     70.8±0.10µs        ? ?/sec    1.00     42.4±0.08µs        ? ?/sec
   filter context fsb with value length 20 high selectivity (kept 1023/1024)     1.67     70.7±0.14µs        ? ?/sec    1.00     42.4±0.06µs        ? ?/sec
   filter context fsb with value length 20 low selectivity (kept 1/1024)         1.66     70.6±0.09µs        ? ?/sec    1.00     42.5±0.79µs        ? ?/sec
   filter context fsb with value length 5 (kept 1/2)                             1.66     70.6±0.10µs        ? ?/sec    1.00     42.5±0.05µs        ? ?/sec
   filter context fsb with value length 5 high selectivity (kept 1023/1024)      1.67     70.7±0.10µs        ? ?/sec    1.00     42.4±0.08µs        ? ?/sec
   filter context fsb with value length 5 low selectivity (kept 1/1024)          1.66     70.6±0.10µs        ? ?/sec    1.00     42.4±0.09µs        ? ?/sec
   filter context fsb with value length 50 (kept 1/2)                            1.66     70.7±0.12µs        ? ?/sec    1.00     42.5±0.08µs        ? ?/sec
   filter context fsb with value length 50 high selectivity (kept 1023/1024)     1.66     70.6±0.11µs        ? ?/sec    1.00     42.4±0.07µs        ? ?/sec
   filter context fsb with value length 50 low selectivity (kept 1/1024)         1.67     70.7±0.09µs        ? ?/sec    1.00     42.4±0.11µs        ? ?/sec
   filter context i32 (kept 1/2)                                                 1.00     19.5±0.08µs        ? ?/sec    1.01     19.7±0.06µs        ? ?/sec
   filter context i32 high selectivity (kept 1023/1024)                          1.06      6.7±0.49µs        ? ?/sec    1.00      6.3±0.36µs        ? ?/sec
   filter context i32 low selectivity (kept 1/1024)                              1.00    233.3±0.26ns        ? ?/sec    1.05    246.1±0.31ns        ? ?/sec
   filter context i32 w NULLs (kept 1/2)                                         1.45     90.6±0.16µs        ? ?/sec    1.00     62.6±0.52µs        ? ?/sec
   filter context i32 w NULLs high selectivity (kept 1023/1024)                  1.01     13.6±0.47µs        ? ?/sec    1.00     13.4±0.42µs        ? ?/sec
   filter context i32 w NULLs low selectivity (kept 1/1024)                      1.05    461.6±0.36ns        ? ?/sec    1.00    439.6±0.69ns        ? ?/sec
   filter context mixed string view (kept 1/2)                                   1.28    112.4±3.37µs        ? ?/sec    1.00     87.8±7.43µs        ? ?/sec
   filter context mixed string view high selectivity (kept 1023/1024)            1.00     58.9±1.69µs        ? ?/sec    1.01     59.4±1.39µs        ? ?/sec
   filter context mixed string view low selectivity (kept 1/1024)                1.10    695.6±1.50ns        ? ?/sec    1.00    634.5±2.26ns        ? ?/sec
   filter context short string view (kept 1/2)                                   1.33    113.7±1.74µs        ? ?/sec    1.00     85.7±6.27µs        ? ?/sec
   filter context short string view high selectivity (kept 1023/1024)            1.00     58.4±1.30µs        ? ?/sec    1.01     58.8±1.47µs        ? ?/sec
   filter context short string view low selectivity (kept 1/1024)                1.11    500.5±0.86ns        ? ?/sec    1.00    452.1±2.39ns        ? ?/sec
   filter context string (kept 1/2)                                              1.04    578.5±7.07µs        ? ?/sec    1.00    556.8±5.12µs        ? ?/sec
   filter context string dictionary (kept 1/2)                                   1.00     20.1±0.05µs        ? ?/sec    1.01     20.2±0.05µs        ? ?/sec
   filter context string dictionary high selectivity (kept 1023/1024)            1.00      7.6±0.42µs        ? ?/sec    1.00      7.6±0.25µs        ? ?/sec
   filter context string dictionary low selectivity (kept 1/1024)                1.00    807.6±1.10ns        ? ?/sec    1.00    811.1±1.13ns        ? ?/sec
   filter context string dictionary w NULLs (kept 1/2)                           1.44     91.3±0.27µs        ? ?/sec    1.00     63.4±0.12µs        ? ?/sec
   filter context string dictionary w NULLs high selectivity (kept 1023/1024)    1.00     14.3±0.55µs        ? ?/sec    1.01     14.5±0.48µs        ? ?/sec
   filter context string dictionary w NULLs low selectivity (kept 1/1024)        1.03   1069.6±2.32ns        ? ?/sec    1.00   1036.6±5.14ns        ? ?/sec
   filter context string high selectivity (kept 1023/1024)                       1.04   663.6±31.75µs        ? ?/sec    1.00   641.1±10.10µs        ? ?/sec
   filter context string low selectivity (kept 1/1024)                           1.04   1098.9±2.48ns        ? ?/sec    1.00   1054.7±3.78ns        ? ?/sec
   filter context u8 (kept 1/2)                                                  1.00     18.9±0.03µs        ? ?/sec    1.00     18.9±0.03µs        ? ?/sec
   filter context u8 high selectivity (kept 1023/1024)                           1.00  1818.9±11.69ns        ? ?/sec    1.02  1855.2±12.60ns        ? ?/sec
   filter context u8 low selectivity (kept 1/1024)                               1.00    229.1±5.14ns        ? ?/sec    1.08    248.4±0.36ns        ? ?/sec
   filter context u8 w NULLs (kept 1/2)                                          1.45     89.9±0.14µs        ? ?/sec    1.00     61.8±0.12µs        ? ?/sec
   filter context u8 w NULLs high selectivity (kept 1023/1024)                   1.00      8.6±0.03µs        ? ?/sec    1.00      8.6±0.02µs        ? ?/sec
   filter context u8 w NULLs low selectivity (kept 1/1024)                       1.05    563.9±6.61ns        ? ?/sec    1.00    535.6±0.90ns        ? ?/sec
   filter decimal128 (kept 1/2)                                                  1.00     93.0±0.42µs        ? ?/sec    1.04     97.1±0.26µs        ? ?/sec
   filter decimal128 high selectivity (kept 1023/1024)                           1.00     53.0±1.52µs        ? ?/sec    1.01     53.8±1.26µs        ? ?/sec
   filter decimal128 low selectivity (kept 1/1024)                               1.00      2.3±0.01µs        ? ?/sec    1.03      2.4±0.01µs        ? ?/sec
   filter f32 (kept 1/2)                                                         1.00    198.5±0.33µs        ? ?/sec    1.15    228.4±1.44µs        ? ?/sec
   filter fsb with value length 20 (kept 1/2)                                    1.00    146.6±0.44µs        ? ?/sec    1.02    149.0±0.58µs        ? ?/sec
   filter fsb with value length 20 high selectivity (kept 1023/1024)             1.07     73.3±2.10µs        ? ?/sec    1.00     68.4±0.94µs        ? ?/sec
   filter fsb with value length 20 low selectivity (kept 1/1024)                 1.00      2.5±0.00µs        ? ?/sec    1.02      2.6±0.00µs        ? ?/sec
   filter fsb with value length 5 (kept 1/2)                                     1.00    142.2±0.20µs        ? ?/sec    1.08    153.1±0.89µs        ? ?/sec
   filter fsb with value length 5 high selectivity (kept 1023/1024)              1.00     11.0±0.79µs        ? ?/sec    1.06     11.7±0.46µs        ? ?/sec
   filter fsb with value length 5 low selectivity (kept 1/1024)                  1.00      2.4±0.00µs        ? ?/sec    1.04      2.5±0.00µs        ? ?/sec
   filter fsb with value length 50 (kept 1/2)                                    1.00    176.7±0.85µs        ? ?/sec    1.07   188.6±11.58µs        ? ?/sec
   filter fsb with value length 50 high selectivity (kept 1023/1024)             1.00    203.3±3.59µs        ? ?/sec    1.07    217.1±3.83µs        ? ?/sec
   filter fsb with value length 50 low selectivity (kept 1/1024)                 1.00      2.5±0.00µs        ? ?/sec    1.01      2.6±0.00µs        ? ?/sec
   filter i32 (kept 1/2)                                                         1.00     91.1±0.14µs        ? ?/sec    1.04     94.4±0.72µs        ? ?/sec
   filter i32 high selectivity (kept 1023/1024)                                  1.02      8.7±0.37µs        ? ?/sec    1.00      8.5±0.41µs        ? ?/sec
   filter i32 low selectivity (kept 1/1024)                                      1.00      2.5±0.01µs        ? ?/sec    1.02      2.5±0.01µs        ? ?/sec
   filter optimize (kept 1/2)                                                    1.00     82.0±0.37µs        ? ?/sec    1.12     91.8±0.27µs        ? ?/sec
   filter optimize high selectivity (kept 1023/1024)                             1.00      2.6±0.01µs        ? ?/sec    1.01      2.6±0.01µs        ? ?/sec
   filter optimize low selectivity (kept 1/1024)                                 1.00      2.2±0.01µs        ? ?/sec    1.04      2.2±0.01µs        ? ?/sec
   filter run array (kept 1/2)                                                   1.08    471.1±0.99µs        ? ?/sec    1.00    436.8±1.30µs        ? ?/sec
   filter run array high selectivity (kept 1023/1024)                            1.09    448.5±1.25µs        ? ?/sec    1.00    413.4±0.92µs        ? ?/sec
   filter run array low selectivity (kept 1/1024)                                1.11    334.5±0.93µs        ? ?/sec    1.00    300.9±1.19µs        ? ?/sec
   filter single record batch                                                    1.03     94.3±0.20µs        ? ?/sec    1.00     91.5±0.20µs        ? ?/sec
   filter u8 (kept 1/2)                                                          1.00     91.1±0.10µs        ? ?/sec    1.00     91.0±0.33µs        ? ?/sec
   filter u8 high selectivity (kept 1023/1024)                                   1.00      3.7±0.02µs        ? ?/sec    1.00      3.7±0.02µs        ? ?/sec
   filter u8 low selectivity (kept 1/1024)                                       1.03      2.4±0.01µs        ? ?/sec    1.00      2.4±0.00µs        ? ?/sec
   ```
   
   
   </p>
   </details>
   
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2173174118


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -609,8 +617,9 @@ impl<T: ByteViewType + ?Sized> Array for GenericByteViewArray<T> {
 
     fn shrink_to_fit(&mut self) {
         self.views.shrink_to_fit();
-        self.buffers.iter_mut().for_each(|b| b.shrink_to_fit());
-        self.buffers.shrink_to_fit();
+        if let Some(buffers) = Arc::get_mut(&mut self.buffers.0) {

Review Comment:
   The underlying Buffers are reference counted too, and only shrink themselves if the reference count is 1. So while this does change the semantics slightly, I don't think it changes as much in practice: When the Arc is shared, the (current) alternative would be to store references to the same buffers in another Vec - thus incrementing the reference counts on the underlying buffers and making their `shrink_to_fit` a no-op.
   
   That's also why `make_mut` wont lead to more shrinking



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2173174118


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -609,8 +617,9 @@ impl<T: ByteViewType + ?Sized> Array for GenericByteViewArray<T> {
 
     fn shrink_to_fit(&mut self) {
         self.views.shrink_to_fit();
-        self.buffers.iter_mut().for_each(|b| b.shrink_to_fit());
-        self.buffers.shrink_to_fit();
+        if let Some(buffers) = Arc::get_mut(&mut self.buffers.0) {

Review Comment:
   The underlying Buffers are reference counted too, and only shrink themselves if the reference count is 0. So while this does change the semantics slightly, I don't think it changes as much in practice: When the Arc is shared, the (current) alternative would be to store references to the same buffers in another Vec - thus incrementing the reference counts on the underlying buffers and making their `shrink_to_fit` a no-op.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2173187524


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -736,12 +745,18 @@ where
 }
 
 impl<T: ByteViewType + ?Sized> From<GenericByteViewArray<T>> for ArrayData {
-    fn from(mut array: GenericByteViewArray<T>) -> Self {
+    fn from(array: GenericByteViewArray<T>) -> Self {
         let len = array.len();
-        array.buffers.insert(0, array.views.into_inner());
+        let new_buffers = {

Review Comment:
   I can reproduce the slowdown for the concat kernel on my laptop.
   
   For this allocation, I believe we in turn save doing this allocation during `clone()` when using Arc<ViewBuffers>. But your instincts were right, the additional clone was hidden in the `From<ArrayData>` =)



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2167653386


##########
arrow-array/benches/view_types.rs:
##########
@@ -43,6 +43,12 @@ fn criterion_benchmark(c: &mut Criterion) {
             hint::black_box(sliced.gc());
         });
     });
+
+    c.bench_function("view types slice", |b| {

Review Comment:
   https://github.com/apache/arrow-rs/pull/7781



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3005952786

   FYI @XiangpengHao and @Dandandan 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3422189729

   This seems to have come up again in datafusion, see:
   - https://github.com/apache/datafusion/pull/18161


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3677773383

   > That proposal is basically identical to the original PR #7773, where it was requested that the API shouldn't expose Arc<[Buffer]>, hence motivating PR.
   > 
   > Regardless, I'm glad there's progress on this (seamingly simple) change
   
   Yes, sorry I think I dropped the ball with this PR / others. I am sorry about that and hope it is not discouraging to you


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk closed pull request #7773: Continued: Use Arc<[Buffer]> instead of raw Vec<Buffer> in GenericByteViewArray for faster slice
URL: https://github.com/apache/arrow-rs/pull/7773


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2167492034


##########
arrow-array/benches/view_types.rs:
##########
@@ -43,6 +43,12 @@ fn criterion_benchmark(c: &mut Criterion) {
             hint::black_box(sliced.gc());
         });
     });
+
+    c.bench_function("view types slice", |b| {

Review Comment:
   Nice! Is there any chance you can pull this benchmark into its own PR (to make it easier for me to run benchmarks to compare the performance of this PR and main)?



##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -162,7 +164,7 @@ use super::ByteArrayType;
 pub struct GenericByteViewArray<T: ByteViewType + ?Sized> {
     data_type: DataType,
     views: ScalarBuffer<u128>,
-    buffers: Vec<Buffer>,
+    buffers: Arc<[Buffer]>,

Review Comment:
   Would it be possible to use `ViewBuffers` here to keep the encapsulation?



##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -734,12 +743,20 @@ where
 }
 
 impl<T: ByteViewType + ?Sized> From<GenericByteViewArray<T>> for ArrayData {
-    fn from(mut array: GenericByteViewArray<T>) -> Self {
+    fn from(array: GenericByteViewArray<T>) -> Self {
         let len = array.len();
-        array.buffers.insert(0, array.views.into_inner());
+        let new_buffers = {
+            let mut buffers = Vec::with_capacity(array.buffers.len() + 1);
+            buffers.push(array.views.into_inner());
+            for buffer in array.buffers.iter() {
+                buffers.push(buffer.clone());
+            }

Review Comment:
   Since this gets an owned array, I think you can avoid cloning  the buffer here too (`for buffer in array.buffers ...`).
   
   Also, It probably doesnt matter but you can probably use extend here and skip some capacity checks when appending as well
   
   ```suggestion
               buffers.extend(array.buffers)
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3005960410

   🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/gh_compare_arrow.sh) Running
   Linux aal-dev 6.11.0-1015-gcp #15~24.04.1-Ubuntu SMP Thu Apr 24 20:41:05 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
   Comparing arc-buffers (25e215a211007eb3d91938f2a4faf33af9d8656f) to 71ac9bd7146565ab47be8053c412b30c0a4c01c6 [diff](https://github.com/apache/arrow-rs/compare/71ac9bd7146565ab47be8053c412b30c0a4c01c6..25e215a211007eb3d91938f2a4faf33af9d8656f)
   BENCH_NAME=coalesce_kernels
   BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench coalesce_kernels 
   BENCH_FILTER=
   BENCH_BRANCH_NAME=arc-buffers
   Results will be posted here when complete
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3084228965

   🤖: Benchmark completed
   
   <details><summary>Details</summary>
   <p>
   
   
   ```
   group                                                          arc-buffers                            main
   -----                                                          -----------                            ----
   concat 1024 arrays boolean 4                                   1.01     27.9±0.03µs        ? ?/sec    1.00     27.7±0.04µs        ? ?/sec
   concat 1024 arrays i32 4                                       1.05     13.8±0.03µs        ? ?/sec    1.00     13.1±0.02µs        ? ?/sec
   concat 1024 arrays str 4                                       1.03     56.6±0.36µs        ? ?/sec    1.00     54.7±0.39µs        ? ?/sec
   concat boolean 1024                                            1.03    419.9±0.41ns        ? ?/sec    1.00    407.7±0.50ns        ? ?/sec
   concat boolean 8192 over 100 arrays                            1.15     50.9±0.05µs        ? ?/sec    1.00     44.1±0.06µs        ? ?/sec
   concat boolean nulls 1024                                      1.00    743.8±3.48ns        ? ?/sec    1.01    752.0±1.02ns        ? ?/sec
   concat boolean nulls 8192 over 100 arrays                      1.14    109.7±0.20µs        ? ?/sec    1.00     96.1±0.15µs        ? ?/sec
   concat fixed size lists                                        1.00   724.2±17.91µs        ? ?/sec    1.07   775.3±29.75µs        ? ?/sec
   concat i32 1024                                                1.02    441.8±0.82ns        ? ?/sec    1.00    434.5±1.12ns        ? ?/sec
   concat i32 8192 over 100 arrays                                1.07   224.1±11.30µs        ? ?/sec    1.00    210.1±7.19µs        ? ?/sec
   concat i32 nulls 1024                                          1.02    767.0±5.74ns        ? ?/sec    1.00    751.4±6.63ns        ? ?/sec
   concat i32 nulls 8192 over 100 arrays                          1.09   299.6±15.16µs        ? ?/sec    1.00    276.0±9.15µs        ? ?/sec
   concat str 1024                                                1.00     13.7±1.12µs        ? ?/sec    1.03     14.0±1.33µs        ? ?/sec
   concat str 8192 over 100 arrays                                1.00    107.4±0.79ms        ? ?/sec    1.00    107.2±0.74ms        ? ?/sec
   concat str nulls 1024                                          1.05      7.3±1.03µs        ? ?/sec    1.00      7.0±0.86µs        ? ?/sec
   concat str nulls 8192 over 100 arrays                          1.00     18.7±0.11ms        ? ?/sec    2.82     52.9±0.51ms        ? ?/sec
   concat str_dict 1024                                           1.02      2.9±0.02µs        ? ?/sec    1.00      2.8±0.01µs        ? ?/sec
   concat str_dict_sparse 1024                                    1.01      7.0±0.03µs        ? ?/sec    1.00      6.9±0.03µs        ? ?/sec
   concat struct with int32 and dicts size=1024 count=2           1.00      6.6±0.08µs        ? ?/sec    1.00      6.6±0.04µs        ? ?/sec
   concat utf8_view  max_str_len=128 null_density=0               1.00     77.7±0.38µs        ? ?/sec    1.00     77.8±0.51µs        ? ?/sec
   concat utf8_view  max_str_len=128 null_density=0.2             1.01     83.7±0.42µs        ? ?/sec    1.00     83.1±0.21µs        ? ?/sec
   concat utf8_view  max_str_len=20 null_density=0                1.01     77.5±0.43µs        ? ?/sec    1.00     76.6±0.48µs        ? ?/sec
   concat utf8_view  max_str_len=20 null_density=0.2              1.01     83.9±0.29µs        ? ?/sec    1.00     83.1±0.66µs        ? ?/sec
   concat utf8_view all_inline max_str_len=12 null_density=0      1.00     42.0±4.24µs        ? ?/sec    1.14     47.7±3.38µs        ? ?/sec
   concat utf8_view all_inline max_str_len=12 null_density=0.2    1.02     49.0±3.84µs        ? ?/sec    1.00     47.9±3.49µs        ? ?/sec
   ```
   
   
   </p>
   </details>
   
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3084190879

   🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/gh_compare_arrow.sh) Running
   Linux aal-dev 6.11.0-1016-gcp #16~24.04.1-Ubuntu SMP Wed May 28 02:40:52 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
   Comparing arc-buffers (e71a332eba27c8c4b761005fe5d16022773b3bfa) to e42df82a6d1e52f0dbdfa87130c2974ce460af69 [diff](https://github.com/apache/arrow-rs/compare/e42df82a6d1e52f0dbdfa87130c2974ce460af69..e71a332eba27c8c4b761005fe5d16022773b3bfa)
   BENCH_NAME=view_types
   BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench view_types 
   BENCH_FILTER=
   BENCH_BRANCH_NAME=arc-buffers
   Results will be posted here when complete
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#issuecomment-3084289993

   🤖 `./gh_compare_arrow.sh` [Benchmark Script](https://github.com/alamb/datafusion-benchmarking/blob/main/gh_compare_arrow.sh) Running
   Linux aal-dev 6.11.0-1016-gcp #16~24.04.1-Ubuntu SMP Wed May 28 02:40:52 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
   Comparing arc-buffers (e71a332eba27c8c4b761005fe5d16022773b3bfa) to e42df82a6d1e52f0dbdfa87130c2974ce460af69 [diff](https://github.com/apache/arrow-rs/compare/e42df82a6d1e52f0dbdfa87130c2974ce460af69..e71a332eba27c8c4b761005fe5d16022773b3bfa)
   BENCH_NAME=filter_kernels
   BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental --bench filter_kernels 
   BENCH_FILTER=
   BENCH_BRANCH_NAME=arc-buffers
   Results will be posted here when complete
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Continued: Use Arc<[Buffer]> instead of raw Vec in GenericByteViewArray for faster slice [arrow-rs]

Posted by "ctsk (via GitHub)" <gi...@apache.org>.
ctsk commented on code in PR #7773:
URL: https://github.com/apache/arrow-rs/pull/7773#discussion_r2173187524


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -736,12 +745,18 @@ where
 }
 
 impl<T: ByteViewType + ?Sized> From<GenericByteViewArray<T>> for ArrayData {
-    fn from(mut array: GenericByteViewArray<T>) -> Self {
+    fn from(array: GenericByteViewArray<T>) -> Self {
         let len = array.len();
-        array.buffers.insert(0, array.views.into_inner());
+        let new_buffers = {

Review Comment:
   I can reproduce the slowdown for the concat kernel on my laptop.
   
   For this allocation, I believe we in turn save doing this allocation during `clone()` when using Arc<ViewBuffers>...



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org