[ https://issues.apache.org/jira/browse/ARROW-2420?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16430490#comment-16430490 ]
ASF GitHub Bot commented on ARROW-2420: --------------------------------------- pitrou closed pull request #1860: ARROW-2420: [Rust] Fix major memory bug and add benches URL: https://github.com/apache/arrow/pull/1860 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/rust/Cargo.toml b/rust/Cargo.toml index c3120cfdc..4d2476b0c 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 000000000..3d020030e --- /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 000000000..0feb0de0b --- /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 1f2ec6c8d..1cf004fb1 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 c8ba27477..e0b14ddae 100644 --- a/rust/src/builder.rs +++ b/rust/src/builder.rs @@ -84,7 +84,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); + } } } } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > [Rust] Memory is never released > ------------------------------- > > Key: ARROW-2420 > URL: https://issues.apache.org/jira/browse/ARROW-2420 > Project: Apache Arrow > Issue Type: Bug > Components: Rust > Reporter: Andy Grove > Assignee: Andy Grove > Priority: Major > Labels: pull-request-available > Fix For: 0.10.0 > > > Another embarrassing bug ... the code was calling the wrong method to release > memory and wasn't releasing memory. > I have added some benchmarks for testing performance of creating arrays (and > dropping them) and these are working well now after fixing the memory bug. -- This message was sent by Atlassian JIRA (v7.6.3#76005)