Repository navigation
Conversation
Contributor
Author
|
Benchmark results for Results
|
adriangb
force-pushed
the
minify-sizes
branch
from
November 11, 2026 23:14
2d34e28 to
d1dd683
Compare
Sliced arrays and view arrays can keep memory alive that their rows do not reference. Callers such as spilling and IPC writers each work around this on their own. `minify` returns a logically equal array with offset zero whose buffers hold only referenced data. This commit adds the reuse policy and the null buffer handling, and supports the flat types: primitive, temporal, decimal, interval, boolean, null, fixed size binary, byte and byte view arrays. Null rows of byte arrays get empty ranges. `view_data_len` and `keeps_view_buffers` hold the view array decision, so that later code can share it. The dispatch matches every `DataType` variant without a wildcard, so a new variant in arrow-schema fails to compile until `minify` handles it. Nested, union, dictionary and run-end encoded types return `NotYetImplemented`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oded types in `minify` Sliced lists and maps share the full child array. Dictionaries can hold values that no key references, and dense unions can hold child rows that no row references. `minify` needs to recurse into these types to drop that memory. This commit adds List, LargeList, Map, FixedSizeList, Struct, ListView, LargeListView, sparse and dense Union, Dictionary and RunEndEncoded. Null rows of lists and maps get empty ranges. These types share one gather path, `gather_ranges`. It gathers dense unions, list views and run-end encoded arrays by their parts, so child rows that several rows share stay shared. `list_view_child` and `dense_union_rows` hold the child row selection of list views and dense unions, so that later code can share it. `minify`, `gathers_parts` and `gather_ranges` match every `DataType` variant without a wildcard. The dispatch passes the list field and the union fields to the helpers, so they need no `unreachable!` arm. Invalid dictionary key, run end and time unit types return `InvalidArgumentError`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The `minify` kernel has no benchmarks, so performance changes cannot be measured. This adds `minify_kernels` with slices of 8192 rows from parents of 100k rows for each main type, an already minimal input, null-heavy strings with non-empty null ranges, and one large 4M-row case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adriangb
force-pushed
the
minify-sizes
branch
from
November 12, 2026 00:22
d1dd683 to
18fd075
Compare
adriangb
force-pushed
the
minify-sizes
branch
from
November 12, 2026 01:45
18fd075 to
bcd9ea7
Compare
…iased buffers Review found inputs where `minify` kept or created memory that the rows do not need. Repeated views counted shared bytes once per view, so `minify` kept a 1 MB buffer for 100 distinct bytes or made `gc` write the bytes once per view. Null view rows kept their bytes. The slack of 64 bytes per data buffer kept thousands of unreferenced small buffers. A buffer aliased twice inside one array was copied twice, so memory grew. The dense union lookup table was as long as the child. View arrays now merge the distinct ranges that valid views reference. `minify` keeps a data buffer only if the views reference all of its bytes and it is not oversized. It copies the other ranges once into new buffers and gives null rows an empty view. Equal struct columns share one minified column. If the result still uses more memory than the input, `minify` returns the input unchanged. The dense union table spans only the visible offsets. The module doc lists the parents that keep child data of null rows. The `allocated` test helper counts each allocation once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adriangb
force-pushed
the
minify-sizes
branch
from
November 13, 2026 23:38
bcd9ea7 to
04149cf
Compare
…in `minify` `gather_run` copied a run value once per gathered range. A list whose null rows keep their child ranges, or a dense union over a run-end encoded child, then gathered many ranges of one run. A 183 KB input reached a 1 GB peak, and the fallback returned the input unchanged although nothing was aliased. A range that starts in the run where the previous range ended now extends that run. Dense union child rows are numbered in ascending order, so gathered ranges never go back and coalesce. The offsets keep the logical rows unchanged, and a child that is used in full stays shared. `view_data` adds view offsets and lengths as `usize`, because a data buffer can be longer than `u32::MAX`. Dictionary garbage collection costs O(keys + span of used keys) and not O(values). New tests pin the run fix, the view range math, the fallback threshold, the null comparisons of `same_data`, the paths for all-valid null buffers, `push_range`, `gathers_parts` and the exact byte capacity of a gather. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cases cover already compact arrays, small slices of large utf8, view, dictionary and dense union parents, reversed views and arrays with one data buffer per row. `gc`, `take` and `garbage_collect_dictionary` run as baselines that do comparable work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ize` next to `minify` DataFusion needs to know how large an array would be after `minify` without the copy. It splits large batches into pieces under a byte limit for spilling, and it predicts the decoded size of a spill. Operators that build output with `take` or `interleave` also need per-row sizes to know when their output reaches a byte limit. `compacted_size` returns the buffer bytes of `minify` exactly. It walks the array like `minify` and calls the same selection helpers. It models `minify` of gathered rows with a list of row ranges, so nested arrays, dictionaries, dense unions and runs follow the same path as in `minify`. `row_sizes` adds the compacted bytes of each row to a slice, so a caller can sum the columns of a batch. Shared data (dictionary values, runs, dense union child rows, overlapping list views and shared view bytes) counts once for each row that references it. The doc comment states the error bound against `compacted_size` of a slice. `split_by_size` cuts rows into ranges under a byte limit. A seeded random test generates arrays of every supported type with random nulls, null ranges, slices and nesting. It checks `compacted_size` against `minify` and the row size bound on random slices. Set `MINIFY_SIZES_ITERATIONS` and `MINIFY_SIZES_SEED` for a longer run. Both size walks match every `DataType` variant without a wildcard, like `minify`, so a new variant fails to compile until they handle it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Callers choose between `compacted_size` and `minify` by cost, so the benchmark runs `minify`, `compacted_size` and `row_sizes` on the same inputs. It adds slices of boolean, fixed size binary, fixed size list, view and struct arrays. The existing `minify` benchmarks keep their names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`minify` gives a null view row an empty view, but `row_sizes` charged its bytes. Now a null view row pays only its view. `split_by_size` and the `row_sizes` sums overflowed on large sizes. They now saturate, and `split_by_size` starts a new range when the sum would overflow. The docs now say that a range of `split_by_size` can compact to more than `max_size`, that shared data can make every range one row long, and that `compacted_size` is unpadded buffer bytes and not an IPC size. Tests pin the view sizes over many small buffers and over shared bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cted_size` `row_sizes` sized every dictionary value and every dense union child row, so a 100 row slice of a dictionary with 10M values took 28 ms and 80 MB. `add_dictionary` and the dense union arm now size only the span between the smallest and largest used key or offset. `dictionary_size` builds one mask over the span of the used keys, as `minify` does. Tests pin the sizes of small slices of large parents, and the sizes of many gathered ranges in one run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adriangb
force-pushed
the
minify-sizes
branch
2 times, most recently
from
November 14, 2026 01:24
7e93f2e to
ea3c990
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Stacked on #12184. GitHub cannot stack a PR on another PR from a fork, so this PR targets
main. Please review only the 4 commits after the 6minifycommits:compacted_size,row_sizesandsplit_by_sizewith their testscompacted_sizeandrow_sizeswithminifyrow_sizesandcompacted_sizesize only the used span of dictionary values and dense union child rowsRationale for this change
Callers often need the size of an array after
minifywithout paying for the copy. Examples are splitting a large batch into pieces under a byte limit before writing it, and knowing when an output builder has collected enough rows.get_slice_memory_sizecannot answer this. It counts list children, list view children, dense union children, run-end encoded values, dictionary values and view data buffers in full.What changes are included in this PR?
Three functions in
arrow_select::minify:compacted_size(&dyn Array) -> Result<usize, ArrowError>returns the exact buffer bytes thatminifyproduces, without copying. It counts unpadded buffer lengths, not the size of an IPC message.row_sizes(&dyn Array, &mut [u64]) -> Result<(), ArrowError>adds the compacted size of each row into the slice. A caller can sum all columns of a batch into one slice.split_by_size(&[u64], max_size) -> Vec<Range<usize>>splits rows greedily into ranges undermax_size. A row larger than the limit gets its own range.minifyand the size functions share the helpers that decide which rows and bytes are used, so they cannot disagree.row_sizescharges shared data (dictionary values, run-end encoded runs, shared dense union child rows, overlapping list views, shared view bytes) to every row that references it. It can overestimate for long runs or for large dictionary values that many rows reference, and thensplit_by_sizecan return one row per range. It can also underestimate by a small fixed amount per range: each offset buffer holds one offset more than its rows, and each bitmap can need one byte more than its charge. Somax_sizeis a target, not a hard cap. The doc comments ofrow_sizesandsplit_by_sizestate the bound. Null rows of byte and byte view arrays pay no value bytes, becauseminifyempties them.Are these changes tested?
Yes. Unit tests check exact values. A seeded random test over every supported type checks that
compacted_size(a)equals the buffer bytes ofminify(a), and that the sum ofrow_sizesover a range stays within the documented bound ofcompacted_sizeof that slice. Fuzzing, longer property runs and mutation testing were run outside the repository, and their findings are in the unit tests.Are there any significant user-facing changes?
New public API only:
compacted_size,row_sizesandsplit_by_sizeinarrow_select::minify.AI usage disclosure
Claude Code wrote the implementation, tests and this description under my direction.
🤖 Generated with Claude Code