You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ap...@apache.org on 2018/04/09 12:57:15 UTC

[arrow] branch master updated: ARROW-2420: [Rust] Fix major memory bug and add benches

This is an automated email from the ASF dual-hosted git repository.

apitrou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 5030e23  ARROW-2420: [Rust] Fix major memory bug and add benches
5030e23 is described below

commit 5030e235047bdffabf6a900dd39b64eeeb96bdc8
Author: Andy Grove <an...@gmail.com>
AuthorDate: Mon Apr 9 14:57:06 2018 +0200

    ARROW-2420: [Rust] Fix major memory bug and add benches
    
    Author: Andy Grove <an...@gmail.com>
    
    Closes #1860 from andygrove/benches and squashes the following commits:
    
    9cdfce1 <Andy Grove> rustfmt
    123bc86 <Andy Grove> add benchmark for creating array from builder
    cdfe796 <Andy Grove> Add first benches and fix bug where memory was never released
---
 rust/Cargo.toml                    | 13 +++++++++-
 rust/benches/array_from_builder.rs | 49 ++++++++++++++++++++++++++++++++++++++
 rust/benches/array_from_vec.rs     | 42 ++++++++++++++++++++++++++++++++
 rust/src/buffer.rs                 |  5 +++-
 rust/src/builder.rs                |  5 +++-
 5 files changed, 111 insertions(+), 3 deletions(-)

diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index c3120cf..4d2476b 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -36,4 +36,15 @@ path = "src/lib.rs"
 [dependencies]
 bytes = "0.4"
 libc = "0.2"
-serde_json = "1.0.13"
\ No newline at end of file
+serde_json = "1.0.13"
+
+[dev-dependencies]
+criterion = "0.2"
+
+[[bench]]
+name = "array_from_vec"
+harness = false
+
+[[bench]]
+name = "array_from_builder"
+harness = false
\ No newline at end of file
diff --git a/rust/benches/array_from_builder.rs b/rust/benches/array_from_builder.rs
new file mode 100644
index 0000000..3d02003
--- /dev/null
+++ b/rust/benches/array_from_builder.rs
@@ -0,0 +1,49 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#[macro_use]
+extern crate criterion;
+
+use criterion::Criterion;
+
+extern crate arrow;
+
+use arrow::array::*;
+use arrow::builder::*;
+
+fn array_from_builder(n: usize) {
+    let mut v: Builder<i32> = Builder::with_capacity(n);
+    for i in 0..n {
+        v.push(i as i32);
+    }
+    Array::from(v.finish());
+}
+
+fn criterion_benchmark(c: &mut Criterion) {
+    c.bench_function("array_from_builder 128", |b| {
+        b.iter(|| array_from_builder(128))
+    });
+    c.bench_function("array_from_builder 256", |b| {
+        b.iter(|| array_from_builder(256))
+    });
+    c.bench_function("array_from_builder 512", |b| {
+        b.iter(|| array_from_builder(512))
+    });
+}
+
+criterion_group!(benches, criterion_benchmark);
+criterion_main!(benches);
diff --git a/rust/benches/array_from_vec.rs b/rust/benches/array_from_vec.rs
new file mode 100644
index 0000000..0feb0de
--- /dev/null
+++ b/rust/benches/array_from_vec.rs
@@ -0,0 +1,42 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#[macro_use]
+extern crate criterion;
+
+use criterion::Criterion;
+
+extern crate arrow;
+
+use arrow::array::*;
+
+fn array_from_vec(n: usize) {
+    let mut v: Vec<i32> = Vec::with_capacity(n);
+    for i in 0..n {
+        v.push(i as i32);
+    }
+    Array::from(v);
+}
+
+fn criterion_benchmark(c: &mut Criterion) {
+    c.bench_function("array_from_vec 128", |b| b.iter(|| array_from_vec(128)));
+    c.bench_function("array_from_vec 256", |b| b.iter(|| array_from_vec(256)));
+    c.bench_function("array_from_vec 512", |b| b.iter(|| array_from_vec(512)));
+}
+
+criterion_group!(benches, criterion_benchmark);
+criterion_main!(benches);
diff --git a/rust/src/buffer.rs b/rust/src/buffer.rs
index 1f2ec6c..1cf004f 100644
--- a/rust/src/buffer.rs
+++ b/rust/src/buffer.rs
@@ -74,7 +74,10 @@ impl<T> Buffer<T> {
 
 impl<T> Drop for Buffer<T> {
     fn drop(&mut self) {
-        mem::drop(self.data)
+        unsafe {
+            let p = mem::transmute::<*const T, *mut libc::c_void>(self.data);
+            libc::free(p);
+        }
     }
 }
 
diff --git a/rust/src/builder.rs b/rust/src/builder.rs
index 58e5a12..832b2a4 100644
--- a/rust/src/builder.rs
+++ b/rust/src/builder.rs
@@ -99,7 +99,10 @@ impl<T> Builder<T> {
 impl<T> Drop for Builder<T> {
     fn drop(&mut self) {
         if !self.data.is_null() {
-            mem::drop(self.data)
+            unsafe {
+                let p = mem::transmute::<*const T, *mut libc::c_void>(self.data);
+                libc::free(p);
+            }
         }
     }
 }

-- 
To stop receiving notification emails like this one, please contact
apitrou@apache.org.