Skip to content

feat(array): name three levels of canonical compaction and use them in the compressor - #10446

Closed
joseph-isaacs wants to merge 23 commits into
developfrom
ji/trim-uncompressed-arrays
Closed

joseph-isaacs wants to merge 23 commits into
developfrom
ji/trim-uncompressed-arrays

Conversation

@joseph-isaacs

@joseph-isaacs joseph-isaacs commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Compaction names three levels of work for Canonical::compact_with. Each level does at least what the previous one does.
    • ZeroCopy never 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.
    • Bounded adds 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.
    • Exact copies 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.
  • All levels are shallow, as compaction was before: children and validity are not visited.
  • Canonical::compact keeps its name and now means Bounded. VarBinViewArray::compact_buffers and its heuristic gate are unchanged for the zstd schemes and the Arrow exporter.
  • CascadingCompressor compacts its inputs with ZeroCopy, and a string or binary array that no scheme beats with Exact.
  • Tests cover each type at each level, including a gap inside a view buffer's used span, a sparse span, a value shared by every row, gapped and sparse lists, and bool bits whose offset spills into an extra byte. Zero-copy view compaction is checked to share the original buffer's memory.

API Changes

  • New: Compaction, Canonical::compact_with, VarBinViewArray::compact_buffers_with, BoolArray::trim_bits_exact.
  • Behavior: Canonical::compact on 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

claude added 6 commits October 9, 2026 11:37
…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>
@joseph-isaacs joseph-isaacs added the changelog/performance A performance improvement label Oct 12, 2026 — with Claude
@codspeed

codspeed Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 10.99%

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚡ 1 improved benchmark
✅ 1920 untouched benchmarks
⏩ 50 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation encode_primitives[f32, (2000, 512)] 274.6 µs 247.4 µs +10.99%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ji/trim-uncompressed-arrays (67ee2d2) with develop (824c922)

Open in CodSpeed

Footnotes

  1. 50 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

joseph-isaacs and others added 13 commits October 12, 2026 12:22
…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>
I, Claude <noreply@anthropic.com>, hereby add my Signed-off-by to this commit: f11e3d8
I, Claude <noreply@anthropic.com>, hereby add my Signed-off-by to this commit: 52eb242

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
Base automatically changed from ji/exact-size-compressor-baseline to develop October 12, 2026 16:20
…ed-arrays

Signed-off-by: Claude <noreply@anthropic.com>

# Conflicts:
#	vortex-compressor/src/compressor/cascade.rs
#	vortex-compressor/src/compressor/tests.rs
@joseph-isaacs
joseph-isaacs enabled auto-merge (squash) October 12, 2026 18:54
`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
@joseph-isaacs joseph-isaacs changed the title feat(compressor): trim canonical arrays and drop dead bytes from uncompressed output feat(array): name three levels of canonical compaction and use them in the compressor Oct 13, 2026
@joseph-isaacs
joseph-isaacs enabled auto-merge (squash) October 13, 2026 13:42
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added the stale This PR is stale and will be auto-closed soon label Nov 4, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions Bot closed this Nov 11, 2026
auto-merge was automatically disabled November 11, 2026 01:31

Pull request was closed

@robert3005 robert3005 reopened this Nov 12, 2026
…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
@joseph-isaacs
joseph-isaacs enabled auto-merge (squash) November 12, 2026 14:42
@github-actions github-actions Bot removed the stale This PR is stale and will be auto-closed soon label Nov 16, 2026
auto-merge was automatically disabled November 23, 2026 14:03

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/performance A performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants