Repository navigation
feat(array): name three levels of canonical compaction and use them in the compressor - #10446
joseph-isaacs wants to merge 23 commits into
Conversation
…ure blocks exactly
Arrow's Parquet reader points each batch's string views into the whole
decompressed page, and VarBinView::slice keeps every buffer, so the
nbytes() of an 8,192-row block of TPC-H l_comment was about 1 MiB for
27 KiB of strings. The repartition writer measured blocks with nbytes(),
so every block already exceeded the 1 MiB minimum and never coalesced.
Rather than trimming buffers on import, which costs a pass over every
imported view array, keep the import zero-copy and let callers that
size blocks ask for a precise measurement:
- `UncompressedSizeInBytes` takes `UncompressedSizeOpts { precision }`.
`Inexact` (the default) keeps today's behaviour and counts every
held buffer. `Exact` counts only the bytes the valid rows reference:
a VarBinView walks its views, a ListView rebuilds to its referenced
elements, nested types forward the precision to their children, and
fixed-width types are the same either way.
- The `Stat::UncompressedSizeInBytes` slot is the exact size. Only the
exact aggregate reads and writes it as `Precision::Exact`; an inexact
measurement is cached as `Precision::Inexact`, an upper bound that
inexact queries reuse and exact queries ignore. `compute_stat`, and so
file statistics, now measure exactly.
- The repartition coalescer measures each block exactly, so view blocks
sharing a large buffer coalesce up to `block_size_minimum`.
Adds a regression test streaming ten 8,192-row view blocks that share a
2 MiB buffer and asserting they coalesce three to a block.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
…tes from uncompressed output The writer caches the exact uncompressed size on every chunk before compression. The compressor now reads that size, computing it without recording anything where it is absent, as the baseline a scheme has to beat, for the full array and for the sampled slices whose views still point at the full array's buffers. Dead bytes in a view array's buffers no longer make a dictionary of distinct strings look like a 20x win. Compaction moves from before scheme selection to after it. A scheme that changes the encoding rebuilds the data it keeps, so its dead bytes are gone for free. An array that keeps its canonical encoding, because no scheme matched, won, or beat the exact size, is compacted when it holds more than its rows reference: buffers used end to end are kept, contiguous ranges are sliced without copying, and the rest rewritten. The previous up-front compaction skipped arrays holding at most 128 bytes per row or with over half their bytes referenced, which let an Arrow page shared by 8,192-row blocks pass through whole. `uncompressed_size_in_bytes_uncached` measures columnar arrays without caching a statistic on them or their children, since an uncompressed leaf is serialized with its statistics and a size the compressor measured for itself would grow the file. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
…fragments The uncompressed size aggregate does not apply to variant arrays, so the coalescer, the compressing layout and the compressor fell over on the first variant chunk. Each now checks the dtype first and sizes an unsupported array by the bytes it holds, as before. The Python dataset test counted 26 fragments, which were the row splits left by string blocks that never coalesced. Measured exactly, the string column's blocks line up with the numeric columns' and the file has 16. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
…ange The compressor baseline and the layout coalescing move to their own changes stacked on this one, and the longest comments are shortened. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
…eference A scheme now competes against the exact uncompressed size of the array, not the buffers it holds, so a view array sharing a decompressed Parquet page no longer makes every scheme look like a win. The repartition writer coalesces blocks by the same measure, so such blocks still reach the block size minimum, and the compressing layout caches the exact size on each chunk for the compressor to read. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
…mpressed output Canonical arrays are trimmed without copying before scheme selection, instead of eagerly compacted. A string or binary array that no scheme beats is compacted on the way out, so the uncompressed output never holds bytes its rows do not reference and the copy is paid at most once. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
The compressor's zero-copy trim was Canonical::compact without the view buffer rewrite. CompactOptions selects that step, so the compressor calls compact_with(CompactOptions::trim()) instead of its own copy. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
Merging this PR will improve performance by 10.99%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
…e flag The exact size of a list view's elements is found by scanning offsets and sizes: lists that tile one contiguous run are measured as a slice of it, fixed-width elements are sized by count, and only overlapping or gapped lists of variable-width elements are rebuilt. The accumulator already caches an exact result through the stat slot, so the cache flag and the uncached variant go. Precision is documented as approximate versus actual bytes used. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
I, Claude <noreply@anthropic.com>, hereby add my Signed-off-by to this commit: 729502c I, Claude <noreply@anthropic.com>, hereby add my Signed-off-by to this commit: 2d03521 I, Claude <noreply@anthropic.com>, hereby add my Signed-off-by to this commit: b840fc0 I, Claude <noreply@anthropic.com>, hereby add my Signed-off-by to this commit: 09ef167 Signed-off-by: Claude <noreply@anthropic.com>
The uncached variant is gone: the writer caches the exact size on each chunk anyway, so the compressor reads and records through the one path. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
I, Claude <noreply@anthropic.com>, hereby add my Signed-off-by to this commit: 3402fe7 Signed-off-by: Claude <noreply@anthropic.com>
…en file The writer now records the exact uncompressed size on each chunk before compression, and the array statistics serializer writes it with the other statistics, so the stock ticker file grows by 24 bytes. The compact strategy writes no such statistics and is unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
…ressor-baseline Signed-off-by: Claude <noreply@anthropic.com>
…ressor-baseline Signed-off-by: Claude <noreply@anthropic.com> # Conflicts: # vortex-file/src/tests.rs
…ed-arrays Signed-off-by: Claude <noreply@anthropic.com> # Conflicts: # vortex-compressor/src/compressor/cascade.rs # vortex-compressor/src/compressor/tests.rs
`Compaction` lets callers choose how much work dropping unreferenced memory is worth, with each level doing at least what the one before does: - `ZeroCopy` never copies data: bool bits are trimmed, list elements outside the referenced span are dropped, and view buffers are sliced to the span their views use. - `Bounded` also rewrites a view buffer under half used, or rebuilds list elements under a tenth used. `Canonical::compact` now means this level. - `Exact` copies whatever it takes for the array's own data to be no larger than its exact uncompressed size: bool bits are realigned when their offset costs a byte, lists that are not zero-copy to a list are rebuilt, and view buffers are rewritten. The compressor compacts inputs with `ZeroCopy` and a string or binary array that no scheme beats with `Exact`, replacing the boolean option this PR introduced and the hand-rolled exact cleanup. Signed-off-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst
|
This PR has been marked as stale because it has been open for 14 days with no activity. Please comment or remove the stale label if you wish to keep it active, otherwise it will be closed in 7 days |
|
This PR was closed because it has been inactive for 7 days since being marked as stale. |
…ed-arrays Keep develop's `Selection` from scheme selection and apply exact view compaction to the selected string array. Port the compaction tests to develop's session, `ListViewArray::new` and always-exact `uncompressed_size_in_bytes` APIs. Signed-off-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst
Pull request was closed
Summary
Third of three stacked PRs, after vortex-data/vortex#10439 and vortex-data/vortex#10445. Slicing and taking share buffers instead of copying, so a canonical array can hold bytes none of its rows reach. Callers need to choose how much work dropping them is worth: the compressor wants the free part only, since most schemes re-encode anyway, while its uncompressed output must hold nothing unreferenced. This adds that choice as three named levels and uses them in the compressor, which then pays the copy at most once.
Changes
Compactionnames three levels of work forCanonical::compact_with. Each level does at least what the previous one does.ZeroCopynever copies data. Bool bits are trimmed to their bytes, list elements outside the referenced span are dropped, and each view buffer is sliced to the span its views use, with unused buffers dropped.Boundedadds copying only where that frees more than it copies: a view buffer under half used, or list elements under a tenth used (the rule the Arrow and DuckDB exporters already apply), is rewritten.Exactcopies whatever it takes for the array's own data to be no larger than what its rows reference, as the exact uncompressed size counts it: bool bits are realigned when their offset costs a byte, lists that are not zero-copy to a list are rebuilt, and view buffers are rewritten until they hold no more than the bytes their views point at.Canonical::compactkeeps its name and now meansBounded.VarBinViewArray::compact_buffersand its heuristic gate are unchanged for the zstd schemes and the Arrow exporter.CascadingCompressorcompacts its inputs withZeroCopy, and a string or binary array that no scheme beats withExact.API Changes
Compaction,Canonical::compact_with,VarBinViewArray::compact_buffers_with,BoolArray::trim_bits_exact.Canonical::compacton a view array now always measures its buffers, slices them to their used span, and rewrites any under half used, instead of skipping arrays below its old size and waste gates. On a list array that is not zero-copy to a list, it rebuilds the elements when under a tenth of them are referenced.🤖 Generated with Claude Code
https://claude.ai/code/session_015LWq6yREM1uAD9mbD2ZAst
Generated by Claude Code