You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "waynexia (via GitHub)" <gi...@apache.org> on 2025/08/05 00:36:33 UTC
[PR] Expose memory tracking API to Array and ArrayData [arrow-rs]
waynexia opened a new pull request, #8040:
URL: https://github.com/apache/arrow-rs/pull/8040
# Which issue does this PR close?
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax.
- Follow up of #7303
# Rationale for this change
#7303 implements the fundamental symbols for tracking memory. This patch exposes those APIs to a higher level `Array` and `ArrayData`.
# What changes are included in this PR?
New APIs `claim` for `Array` and `ArrayData`. New feature `pool` to `arrow`, `arrow-array` and `arrow-data` for the new API
# Are these changes tested?
Yes, and there is an example to demo basic usage.
# Are there any user-facing changes?
New API and feature
--
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] Expose memory tracking API to Array and ArrayData [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8040:
URL: https://github.com/apache/arrow-rs/pull/8040#issuecomment-3160686181
Thanks @waynexia -- is there a high level description / "[EPIC]" style ticket of what we are doing with these APIs? I think it would be good to make an issue that describes the high level project / direction for wider visibility (and likely to get other people involved)
I found some related issues. Do any of them reflect your plan?
- https://github.com/apache/arrow-rs/issues/6439
- https://github.com/apache/arrow-rs/issues/3960
--
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] Expose memory tracking API to Array and ArrayData [arrow-rs]
Posted by "notfilippo (via GitHub)" <gi...@apache.org>.
notfilippo commented on PR #8040:
URL: https://github.com/apache/arrow-rs/pull/8040#issuecomment-3571468526
👋 I've reheated this PR over at [feat(memory-tracking): expose API to NullBuffer, ArrayData, and Array](https://github.com/apache/arrow-rs/pull/8918). Let me know what you think! :)
--
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] Expose memory tracking API to Array and ArrayData [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8040:
URL: https://github.com/apache/arrow-rs/pull/8040#issuecomment-3207622550
@waynexia I am preparing for another arrow release, hopefully I'll make the RC tomorrow. Would you like to
1. address comments on this PR before merge
2. Merge as is (and maybe address comments later)
3. Wait for the next release
Just let me know
--
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] Expose memory tracking API to Array and ArrayData [arrow-rs]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #8040:
URL: https://github.com/apache/arrow-rs/pull/8040#issuecomment-4805866726
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.
--
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] Expose memory tracking API to Array and ArrayData [arrow-rs]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on PR #8040:
URL: https://github.com/apache/arrow-rs/pull/8040#issuecomment-3183049110
@alamb I think it's mostly https://github.com/apache/arrow-rs/issues/6439 so consumers (like DataFusion) can better keep track memory usage without over-counting memory after e.g. (`.slice`)
--
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] Expose memory tracking API to Array and ArrayData [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8040:
URL: https://github.com/apache/arrow-rs/pull/8040#issuecomment-3725489505
I am trying to clean up the review / merge queue. Given this PR has been open for quite a while, I am marking it as a draft. let's mark it ready for review if we want to proceed
--
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] Expose memory tracking API to Array and ArrayData [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8040:
URL: https://github.com/apache/arrow-rs/pull/8040#discussion_r2283282889
##########
arrow/examples/memory_tracking.rs:
##########
@@ -0,0 +1,65 @@
+// 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.
+
+//! Example demonstrating the Array memory tracking functionality
+
+use arrow_array::{Array, Int32Array, ListArray};
+use arrow_buffer::{MemoryPool, TrackingMemoryPool};
+use arrow_schema::{DataType, Field};
+use std::sync::Arc;
+
+fn main() {
+ let pool = TrackingMemoryPool::default();
+
+ println!("Arrow Array Memory Tracking Example");
+ println!("===================================");
+
+ // Basic array memory tracking
+ let array = Int32Array::from(vec![1, 2, 3, 4, 5]);
+ array.claim(&pool);
+ println!("Int32Array (5 elements): {} bytes", pool.used());
+
+ // Nested array (recursive tracking)
+ let offsets = arrow_buffer::OffsetBuffer::new(vec![0, 2, 4].into());
+ let field = Arc::new(Field::new("item", DataType::Int32, false));
+ let list_array = ListArray::new(field, offsets, Arc::new(array), None);
+
+ let before_list = pool.used();
+ list_array.claim(&pool);
+ let after_list = pool.used();
+ println!("ListArray (nested): +{} bytes", after_list - before_list);
+
+ // No double-counting for derived arrays
+ let large_array = Int32Array::from((0..1000).collect::<Vec<i32>>());
+ large_array.claim(&pool);
+ let original_usage = pool.used();
+ println!("Original array (1000 elements): {original_usage} bytes");
+
+ // Create and claim slices - should not increase memory usage
+ let slice1 = large_array.slice(0, 100);
+ let slice2 = large_array.slice(500, 200);
+
+ slice1.claim(&pool);
+ slice2.claim(&pool);
+ let final_usage = pool.used();
+
+ println!("After claiming 2 slices: {final_usage} bytes");
Review Comment:
I think these should actually test the bytes used (not just print them out)
##########
arrow-array/src/array/mod.rs:
##########
@@ -336,6 +336,34 @@ pub trait Array: std::fmt::Debug + Send + Sync {
/// This value will always be greater than returned by `get_buffer_memory_size()` and
/// includes the overhead of the data structures that contain the pointers to the various buffers.
fn get_array_memory_size(&self) -> usize;
+
+ /// Claim memory used by this array in the provided memory pool.
+ ///
+ /// This recursively claims memory for:
+ /// - All data buffers in this array
+ /// - All child arrays (for nested types like List, Struct, etc.)
+ /// - The null bitmap buffer if present
+ ///
+ /// This method guarantees that the memory pool will only compute occupied memory
+ /// exactly once. For example, if this array is derived from operations like `slice`,
+ /// calling `claim` on it would not change the memory pool's usage if the underlying buffers
+ /// are already counted before.
+ ///
+ /// # Example
+ /// ```
+ /// # use arrow_array::{Int32Array, Array};
+ /// # use arrow_buffer::TrackingMemoryPool;
+ ///
+ /// let array = Int32Array::from(vec![1, 2, 3, 4, 5]);
+ /// let pool = TrackingMemoryPool::default();
+ ///
+ /// // Claim the array's memory in the pool
+ /// array.claim(&pool);
Review Comment:
Could you also add an example (either here or elsewhere) of how one would use `claim`?
For example, if we now did
```rust
let array2 = array1.slice(0, 1);
```
Is the idea that now array2.array_memory_size() would be zero?
##########
arrow/examples/memory_tracking.rs:
##########
@@ -0,0 +1,65 @@
+// 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.
+
+//! Example demonstrating the Array memory tracking functionality
+
+use arrow_array::{Array, Int32Array, ListArray};
+use arrow_buffer::{MemoryPool, TrackingMemoryPool};
+use arrow_schema::{DataType, Field};
+use std::sync::Arc;
+
+fn main() {
Review Comment:
Yes, please -- I think it would be much easier to find as an doc test -- perhaps you could just move it to `Array::claim`
--
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] Expose memory tracking API to Array and ArrayData [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8040:
URL: https://github.com/apache/arrow-rs/pull/8040#issuecomment-3188365659
> @alamb I think it's mostly #6439 so consumers (like DataFusion) can better keep track memory usage without over-counting memory after e.g. (`.slice`)
Sounds like a great idea -- thank you @waynexia and @Dandandan
I am quite backed up reviewing other projects and PRs , but will try and review this one over the next few days. Any help reviewing would be most apprecaited.
I filed a epic ticket to track this project, and maybe we can use that to help organize our work a bit better
- https://github.com/apache/arrow-rs/issues/8137
--
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] Expose memory tracking API to Array and ArrayData [arrow-rs]
Posted by "alchemist51 (via GitHub)" <gi...@apache.org>.
alchemist51 commented on PR #8040:
URL: https://github.com/apache/arrow-rs/pull/8040#issuecomment-3365355644
Is it being currently worked upon? I can help in moving this PR forward @waynexia @Dandandan @alamb
--
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] Expose memory tracking API to Array and ArrayData [arrow-rs]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #8040:
URL: https://github.com/apache/arrow-rs/pull/8040#discussion_r2272752863
##########
arrow/examples/memory_tracking.rs:
##########
@@ -0,0 +1,65 @@
+// 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.
+
+//! Example demonstrating the Array memory tracking functionality
+
+use arrow_array::{Array, Int32Array, ListArray};
+use arrow_buffer::{MemoryPool, TrackingMemoryPool};
+use arrow_schema::{DataType, Field};
+use std::sync::Arc;
+
+fn main() {
Review Comment:
Could we write this as a (doc?)test instead (or as well)?
--
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] Expose memory tracking API to Array and ArrayData [arrow-rs]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #8040: Expose memory tracking API to Array and ArrayData
URL: https://github.com/apache/arrow-rs/pull/8040
--
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