You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/09/05 14:11:44 UTC

[GitHub] [arrow] nevi-me commented on a change in pull request #8116: ARROW-9919: [Rust][DataFusion] Speedup math operations by 15%+

nevi-me commented on a change in pull request #8116:
URL: https://github.com/apache/arrow/pull/8116#discussion_r483954060



##########
File path: rust/datafusion/src/physical_plan/math_expressions.rs
##########
@@ -19,23 +19,25 @@
 
 use crate::error::{ExecutionError, Result};
 
-use arrow::array::{Array, ArrayRef, Float32Array, Float64Array, Float64Builder};
+use arrow::array::{Array, ArrayRef, Float32Array, Float64Array};
 
 use arrow::datatypes::DataType;
 
 use std::sync::Arc;
 
 macro_rules! compute_op {
     ($ARRAY:expr, $FUNC:ident, $TYPE:ident) => {{
-        let mut builder = Float64Builder::new($ARRAY.len());
-        for i in 0..$ARRAY.len() {
-            if $ARRAY.is_null(i) {
-                builder.append_null()?;
-            } else {
-                builder.append_value($ARRAY.value(i).$FUNC() as f64)?;
-            }
-        }
-        Ok(Arc::new(builder.finish()))
+        let result: Float64Array = (0..$ARRAY.len())
+            .map(|i| {

Review comment:
       You could likely improve performance further by computing without checking nullity of array, and then building the array using the input bitmask.
   
   I'm away from home, so I don't have a PC to check with; but look at the pattern that most of the compute functions follow.
   
   Removing the if/else allows the compiler to vectorise the loop.




----------------------------------------------------------------
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.

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