adriangb commented on code in PR #12184:
URL: https://github.com/apache/arrow-rs/pull/12184#discussion_r4722416968


##########
arrow-select/src/minify.rs:
##########
@@ -0,0 +1,2608 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for 
additional information regarding copyright ownership
+// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) 
under one or more contributor license agreements
+
+//! [`minify`]: Copy an array into buffers that hold only the data its rows 
reference
+//!
+//! Arrays often keep memory alive that their visible rows do not use:
+//!
+//! * A sliced array shares the buffers of the original, unsliced array.
+//! * A sliced list, map or byte array shares the full child array or value 
buffer.
+//! * A view array can reference a small part of large data buffers.
+//! * A dictionary can hold values that no key references.
+//! * A dense union can hold child rows that no row references.
+//!
+//! [`minify`] returns a logically equal array without this unused memory.
+//!
+//! # Reuse policy
+//!
+//! [`minify`] copies a buffer only when its allocation is larger than the
+//! visible data needs (rounded up to 64 bytes). Otherwise it reuses the buffer
+//! without a copy. This makes `minify` cheap on an array that is already
+//! minimal, and calling it twice copies nothing the second time.
+//!
+//! A buffer that other arrays share counts as too large when its allocation
+//! is larger than the visible data. `minify` copies it, so the total memory in
+//! use can grow until the other arrays drop the shared buffer.
+//!
+//! A buffer can also appear more than once inside `array`, for example in
+//! two struct columns over the same array, or in two dictionaries over the
+//! same values. Struct columns over the same rows of the same buffers share
+//! one minified column. In other cases `minify` can copy the buffer once per
+//! reference. If the result then uses more memory than `array` (beyond 64
+//! bytes per allocation), `minify` returns `array` unchanged.
+//!
+//! # Null rows
+//!
+//! `minify` gives every null row of a byte, list, map or list view array an
+//! empty value range, and every null row of a byte view array an empty view.
+//! The child array or value buffers then hold only the data of valid rows.
+//!
+//! An O(rows) check over the offsets and the null bitmap finds out if any null
+//! row has a non-empty range. If none has, `minify` copies or slices the
+//! referenced range in one piece. Otherwise it copies the ranges of each run 
of
+//! valid rows.
+//!
+//! # Limitations
+//!
+//! * `minify` does not deduplicate dictionary values or merge equal runs.

Review Comment:
   Agreed, I think that's worth a follow-up. I'll file an issue if this merges.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to