Skip to content

Complete blocked FoR compute kernels and selector - #11906

Open
lwwmanning wants to merge 35 commits into
wm/retire-bitpacked-v2from
wm/for-v2-complete
Open

lwwmanning wants to merge 35 commits into
wm/retire-bitpacked-v2from
wm/for-v2-complete

Conversation

@lwwmanning

@lwwmanning lwwmanning commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Completes blocked FoR (fastlanes.for.v2) by adding native blocked compute kernels (filter via chunked SIMD compaction, take, constant compare with per-block range pruning, is_constant, and is_sorted), declaring fastlanes.for.v2 in UNSTABLE, and enabling the guarded 8x1,024 locality selector with nonlinear patch-density penalty and RunEnd.ends exclusion in CompressionSession::default(). Residuals stay at the logical integer type (cascaded BitPacked packs them to their bit width), keeping fastlanes.for.v2 metadata offset-only with no separate for.v3 wire ID.

Benchmarks (for_compute, 65,536 climbing i64s, 7-bit residuals): blocked compare_eq 13.2x faster (2.81 vs 37.24 us), compare_lt 13.7x faster (3.08 vs 42.35 us), is_constant early exit 9.7x faster (2.49 vs 24.04 us), and is_sorted 1.30x faster (34.50 vs 44.77 us) than decode fallback.

Stacked on #11905

Authored with AI assistance.


Devin Review

@lwwmanning lwwmanning added the changelog/feature A new feature label Nov 24, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T12:40:29.031093Z 829b64e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lwwmanning

lwwmanning commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Local 110-Column Integer/Temporal Ablation Results (Release, MiMalloc, Apple M4 Max)

All 110 columns passed bit-exact round-trip verification, and all 13 timed columns passed bit-exact verification across decode, filter(1%, 10%, 50%), take(1%, 10%, 50%), compare, is_constant, and is_sorted.

Corpus Totals (110 Columns: 97 Native Int + 13 Timestamp/Date)

Arm All 110 Cols (B) vs v1_nodelta Native Int (B) vs v1_nodelta TS/Date (B) vs v1_nodelta
default_for_v1_nodelta 859,967,213 +0.00% 539,793,608 +0.00% 320,173,605 +0.00%
btr_for_v2_nodelta 846,423,838 −1.57% 529,651,355 −1.88% 316,772,483 −1.06%
default_for_v1_delta 792,343,521 −7.86% 490,066,759 −9.21% 302,276,762 −5.59%
btr_for_v2_delta 793,413,497 −7.74% 489,339,503 −9.35% 304,073,994 −5.03%

Per-Column Size Diffs (btr_for_v2_nodelta vs default_for_v1_nodelta — 0 regressions)

Column v1_nodelta (B) v2_nodelta (B) Delta Encoding (v1 -> v2)
bimbo.Dev_uni_proxima 10,442,948 6,953,650 −33.41% vortex.sparse -> vortex.sparse
tpch_lineitem.l_orderkey 8,625,920 6,563,200 −23.91% vortex.runend -> vortex.runend
tpch_orders.o_orderkey 4,312,960 2,250,240 −47.83% bp.v1(bw=23) -> for.v2<u16>(bp.v1(bw=12);refs=vortex.sequence)
euro2016.tweeted_at 10,778,892 9,465,614 −12.18% for.v1(bp.v1(bw=42)) -> for.v2(bp.v1(bw=36,p=17458);refs=bp.v1(bw=51))
euro2016.id 6,416,000 5,195,978 −19.02% bp.v1(bw=25) -> for.v2(bp.v1(bw=20,p=6596);refs=bp.v1(bw=25))
airquality.KafkaTimestamp 5,255,040 4,334,120 −17.52% for.v1(bp.v1(bw=51)) -> for.v2(bp.v1(bw=42);refs=vortex.primitive)
airquality.timestamp 5,255,040 4,334,120 −17.52% for.v1(bp.v1(bw=51)) -> for.v2(bp.v1(bw=42);refs=vortex.primitive)
hashtags.twitter#in_reply_to_user_id 701,203 487,082 −30.54% bp.v1(bw=0,p=53022) -> for.v2<u32>(bp.v1(bw=0,p=52367);refs=bp.v1(bw=25,p=1))
airquality.p_0_5 1,034,848 840,282 −18.80% bp.v1(bw=10,p=473) -> for.v2(bp.v1(bw=8,p=2199);refs=bp.v1(bw=9,p=1))
hashtags.Calculation_6610227171140491 2,688,000 2,512,148 −6.54% for.v1(bp.v1(bw=42)) -> for.v2(bp.v1(bw=39,p=929);refs=vortex.primitive)
airquality.p_0_3 1,190,478 1,020,810 −14.25% bp.v1(bw=11,p=9238) -> for.v2(bp.v1(bw=9,p=15071);refs=bp.v1(bw=11,p=1))
airquality.pm_10 477,850 342,078 −28.41% bp.v1(bw=4,p=10680) -> for.v2(bp.v1(bw=3,p=5135);refs=vortex.dict)
airquality.pm_10_atmosphere 477,850 342,078 −28.41% bp.v1(bw=4,p=10680) -> for.v2(bp.v1(bw=3,p=5135);refs=vortex.dict)
airquality.pm_2_5 455,638 332,088 −27.12% bp.v1(bw=4,p=6978) -> for.v2(bp.v1(bw=3,p=3470);refs=vortex.dict)
airquality.pm_2_5_atmosphere 455,638 332,088 −27.12% bp.v1(bw=4,p=6978) -> for.v2(bp.v1(bw=3,p=3470);refs=vortex.dict)
airquality.pm_1 418,408 318,477 −23.88% bp.v1(bw=4,p=773) -> for.v2(bp.v1(bw=3,p=1223);refs=bp.v1(bw=3,p=6))
airquality.pm_1_atmosphere 418,408 318,477 −23.88% bp.v1(bw=4,p=773) -> for.v2(bp.v1(bw=3,p=1223);refs=bp.v1(bw=3,p=6))
arade.F3 994,560 924,408 −7.05% vortex.runend -> vortex.runend
hashtags.Contains: RookieBlue (copy 5) 70,532 63,224 −10.36% vortex.sparse -> vortex.sparse
hashtags.Contains: Motive (copy 2) 21,892 19,624 −10.36% vortex.sparse -> vortex.sparse
hashtags.Contains: TheNeighbors (copy 3) 14,596 13,540 −7.23% vortex.sparse -> vortex.sparse

Representative Kernel Timings (Release Medians in ms; sca in ns/probe over 4,096 random probes)

Column Arm Bytes Enc Dec sca (ns) f1% f10% f50% t1% t10% t50% Cmp Encoding
bimbo.Cliente_ID v1_noD 72,178,568 579.31 58.86 2107.7 12.19 31.31 46.76 12.22 56.03 125.52 37.17 vortex.runend
v2_noD 72,178,568 574.22 58.57 2052.7 12.57 31.31 46.71 12.26 55.61 124.07 37.49 vortex.runend
forced_v2 216,612,686 112.50 12.91 470.7 8.48 19.71 17.55 8.19 42.72 37.55 9.98 for.v2(bp.v1(bw=23,p=323432);refs=bp.v1(bw=19,p=454))
bimbo.Venta_uni_hoy v1_noD 60,482,884 207.38 5.08 221.0 8.34 16.68 12.43 11.31 59.38 15.34 5.28 bp.v1(bw=6,p=759610)
v2_noD 60,482,884 207.41 5.27 202.6 8.06 16.84 12.46 11.07 59.30 15.68 5.15 bp.v1(bw=6,p=759610)
forced_v2 60,763,575 98.35 5.26 430.2 8.35 17.12 14.75 11.32 61.92 28.16 5.51 for.v2(bp.v1(bw=6,p=756569);refs=bp.v1(bw=1,p=4))
euro2016.id v1_noD 6,416,000 27.27 0.19 30.0 0.09 0.44 0.39 0.04 0.29 0.47 0.23 bp.v1(bw=25)
v2_noD 5,195,978 29.44 0.19 243.3 0.17 0.46 0.43 0.23 1.65 0.84 0.02 for.v2(bp.v1(bw=20,p=6596);refs=bp.v1(bw=25))
forced_v2 5,208,008 3.03 0.19 209.2 0.16 0.47 0.41 0.26 1.74 0.87 0.02 for.v2(bp.v1(bw=20,p=6596);refs=bp.v1(bw=25))
euro2016.tweeted_at v1_noD 10,778,892 11.82 0.51 119.4 0.11 0.82 0.93 0.05 0.60 1.02 0.56 for.v1(bp.v1(bw=42))
v2_noD 9,465,614 15.49 0.54 259.6 0.16 0.60 0.90 0.17 1.14 1.25 0.04 for.v2(bp.v1(bw=36,p=17458);refs=bp.v1(bw=51))
forced_v2 9,731,891 5.61 0.51 329.1 0.24 0.68 0.99 0.15 0.93 1.24 0.04 for.v2(bp.v1(bw=36,p=17458);refs=for.v1(bp.v1(bw=42)))
airquality.KafkaTimestamp v1_noD 5,255,040 8.51 0.19 65.1 0.03 0.22 0.38 0.02 0.22 0.33 0.24 for.v1(bp.v1(bw=51))
v2_noD 4,334,120 8.91 0.16 67.8 0.04 0.23 0.33 0.02 0.27 0.43 0.00 for.v2(bp.v1(bw=42);refs=vortex.primitive)
forced_v2 4,334,120 0.90 0.16 68.9 0.03 0.25 0.34 0.02 0.26 0.46 0.00 for.v2(bp.v1(bw=42);refs=vortex.primitive)
airquality.pm_10 v1_noD 477,850 3.09 0.03 146.4 0.04 0.12 0.09 0.07 0.35 0.15 0.07 bp.v1(bw=4,p=10680)
v2_noD 342,078 3.16 0.04 290.3 0.04 0.12 0.09 0.06 0.35 0.29 0.05 for.v2(bp.v1(bw=3,p=5135);refs=vortex.dict)
forced_v2 346,908 1.11 0.04 267.0 0.04 0.14 0.09 0.06 0.37 0.32 0.05 for.v2(bp.v1(bw=3,p=5135);refs=vortex.dict)
airquality.pm_10_atmosphere v1_noD 477,850 3.06 0.03 146.5 0.04 0.13 0.09 0.06 0.35 0.15 0.06 bp.v1(bw=4,p=10680)
v2_noD 342,078 3.24 0.04 256.4 0.04 0.12 0.09 0.05 0.36 0.28 0.05 for.v2(bp.v1(bw=3,p=5135);refs=vortex.dict)
forced_v2 346,908 1.21 0.04 265.9 0.04 0.11 0.09 0.06 0.34 0.29 0.05 for.v2(bp.v1(bw=3,p=5135);refs=vortex.dict)
airquality.p_0_3 v1_noD 1,190,478 2.32 0.04 159.0 0.05 0.17 0.10 0.06 0.28 0.15 0.07 bp.v1(bw=11,p=9238)
v2_noD 1,020,810 2.53 0.05 309.1 0.05 0.13 0.13 0.08 0.31 0.29 0.06 for.v2(bp.v1(bw=9,p=15071);refs=bp.v1(bw=11,p=1))
forced_v2 1,025,640 1.10 0.05 325.6 0.05 0.15 0.13 0.08 0.29 0.29 0.06 for.v2(bp.v1(bw=9,p=15071);refs=bp.v1(bw=11,p=1))
airquality.p_0_5 v1_noD 1,034,848 2.41 0.04 152.8 0.04 0.13 0.07 0.03 0.17 0.14 0.05 bp.v1(bw=10,p=473)
v2_noD 840,282 2.64 0.04 284.5 0.03 0.12 0.08 0.03 0.25 0.28 0.03 for.v2(bp.v1(bw=8,p=2199);refs=bp.v1(bw=9,p=1))
forced_v2 845,112 1.10 0.04 283.3 0.03 0.09 0.07 0.03 0.25 0.28 0.03 for.v2(bp.v1(bw=8,p=2199);refs=bp.v1(bw=9,p=1))
taxi.trip_time v1_noD 31,086,700 47.25 7.84 200.9 1.85 5.44 9.31 2.65 15.78 10.86 3.94 bp.v1(bw=12,p=191110)
v2_noD 31,086,700 47.38 8.01 205.4 1.88 5.22 9.16 2.51 15.66 10.98 3.97 bp.v1(bw=12,p=191110)
forced_v2 29,901,240 28.87 3.53 291.8 2.22 5.71 9.87 2.33 11.14 8.13 1.36 for.v2<u16>(bp.v1(bw=12,p=168936);refs=bp.v1(bw=8))
tpch_lineitem.l_orderkey v1_noD 8,625,920 40.32 3.27 1045.6 1.10 3.38 5.38 1.24 4.82 11.49 3.53 vortex.runend
v2_noD 6,563,200 40.86 2.84 1070.0 1.04 3.37 5.53 1.07 4.61 12.13 3.34 vortex.runend
forced_v2 8,029,436 9.22 0.95 247.8 0.55 1.80 2.96 0.67 2.74 2.52 0.11 for.v2<u16>(bp.v1(bw=10,p=77134);refs=bp.v1(bw=23))
tpch_lineitem.l_shipdate v1_noD 9,002,496 7.55 0.67 92.4 0.53 1.34 1.22 0.19 0.80 2.02 0.82 for.v1(bp.v1(bw=12))
v2_noD 9,002,496 7.74 0.70 66.9 0.46 1.36 1.27 0.16 0.87 2.02 0.78 for.v1(bp.v1(bw=12))
forced_v2 9,007,872 3.18 0.62 116.0 0.59 1.58 1.25 0.21 0.83 2.39 0.36 for.v2<u16>(bp.v1(bw=12);refs=for.v1(bp.v1(bw=7)))
tpch_orders.o_orderkey v1_noD 4,312,960 11.36 0.33 30.0 0.08 0.67 0.59 0.03 0.48 0.52 0.33 bp.v1(bw=23)
v2_noD 2,250,240 11.88 0.22 72.6 0.07 0.35 0.58 0.04 0.25 0.55 0.01 for.v2<u16>(bp.v1(bw=12);refs=vortex.sequence)
forced_v2 2,250,240 1.10 0.22 73.2 0.14 0.35 0.63 0.04 0.22 0.56 0.01 for.v2<u16>(bp.v1(bw=12);refs=vortex.sequence)

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

I found no correctness bug in the kernels themselves. Pruning uses max_nonwrap, so signed and wrapping references are handled, patches are reapplied after pruning, and sliced offsets and the last partial block follow for_each_packed_chunk. Default output for stable editions does not change, because refine downgrades FoR v2 to v1 unless v2 is allowed.

Three things need changes before this lands:

  1. Narrowing breaks benches/for_decode.rs, which panics at this head (inline).
  2. encoded_bytes changes the wire contract under the unchanged fastlanes.for.v2 ID, and a reader built before this PR misdecodes narrowed files silently instead of failing (inline).
  3. The description claims compare is 11x to 100x faster and decode up to 2.2x faster, but no benchmark lands with it. AGENTS.md asks for the benchmark first, so CodSpeed has a baseline.

Beyond that, 3,317 lines is a lot. The filter and take kernels repeat the same loops four times, patch fixup is written five times, and the selector rests on tuned constants with no data in the repo. The blocked is_constant and is_sorted kernels and the selector heuristics could land later, with numbers.

Comment thread vortex-btrblocks/src/session.rs Resolved
@codspeed

codspeed Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

Warning

vortex-data has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

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

⚠️ 1 benchmark is 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

✅ 2150 untouched benchmarks
🆕 9 new benchmarks
⏩ 179 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
🆕 CPU Simulation compare_eq_blocked_pruned N/A 106.1 µs N/A
🆕 CPU Simulation compare_eq_decode_fallback N/A 797.7 µs N/A
🆕 CPU Simulation compare_lt_blocked_pruned N/A 106.5 µs N/A
🆕 CPU Simulation compare_lt_decode_fallback N/A 773.2 µs N/A
🆕 CPU Simulation is_constant_blocked_early_exit N/A 68.8 µs N/A
🆕 CPU Simulation is_constant_decode_fallback N/A 627.5 µs N/A
🆕 CPU Simulation is_sorted_blocked_true N/A 643.5 µs N/A
🆕 CPU Simulation is_sorted_decode_fallback N/A 926.1 µs N/A
🆕 CPU Simulation decode_blocked_i64 N/A 596.7 µs N/A

Comparing wm/for-v2-complete (086be96) with wm/retire-bitpacked-v2 (c6f2b5e)

Open in CodSpeed

Footnotes

  1. 179 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. ↩

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@lwwmanning

Copy link
Copy Markdown
Contributor Author

@codex review
@claude review

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @lwwmanning's task in 2m 2s —— View job


Review of #11906 at 8a0fae5

  • Gather context (diff vs origin/wm/retire-bitpacked-v2, prior review threads)
  • Check whether earlier findings are resolved
  • Review kernels, narrowing, serialization, selector
  • Post review

I re-checked the earlier findings first, then reviewed the full diff.

Fixed since the last round:

  • Filter UB: FoRPackedSameWidth::decode_chunk now unpacks into an initialized buffer before copying out.
  • Negative residuals: try_bitpack_residuals checks the sign before bit-packing, so compression no longer aborts on wrapped signed residuals. Unsigned residuals skip the check, and the check no longer builds a frequency table.
  • Zero-byte v2 candidates: they now stay eligible (v2_penalized.max(1)).
  • benches/for_decode.rs panic: fixed with match_each_integer_ptype!.
  • Unrefined v2 from schemes(): CompressionSession::default() lists FOR_V1 again and refine upgrades it to v2, so schemes() no longer returns v2 unrefined.
  • Missing compat test: there is now a test that old metadata (encoded_bytes == 0) decodes and that an un-narrowed blocked array round-trips.

I re-read the kernels and found no new correctness bugs:

  • Compare pruning uses max_nonwrap, so packed values cannot wrap, and patches are reapplied after pruning.
  • Chunk boundaries: for_each_packed_chunk yields padded chunk * 1024 ranges, so words[range.start / 64..] lines up even when the array has an offset.
  • Filter patch ranks count correctly in both the galloping branch and the linear branch.
  • Narrowed take with all-null indices returns a zeroed T buffer, not the narrowed child.
  • Blocked is_sorted handles nulls the same way the primitive kernel does.

Still open

1. A wrapped signed residual leaves an uncompressed child that is larger than the input (vortex-btrblocks/src/schemes/integer/for_.rs:255)

  • When it happens: in blocked mode, narrowed_residual_ptype (for_compress.rs:172) leaves the residuals at the full signed width when a block's span is wider than u16/u32. A block whose span exceeds T::MAX then wraps negative.
  • What the code does: it keeps biased as a primitive i32/i64 child, so the output is the raw column plus the references array.
  • Why it slips through: the 8-block sample can miss the wide block, so the selector does not catch it.
  • Suggested fix: in blocked mode, use the unsigned type of the same width (i32→u32, i64→u64) for residuals. Within a block, max - min always fits in that type, so residuals can never be negative, and both the fallback and the has_negative_residuals probes for v2 could go away. is_valid_encoded_ptype (vtable/mod.rs:223) would need to allow an unsigned type of equal width, not only a narrower one.
  • Fix this →

2. compress() runs evaluate_v2_on_sample a second time (for_.rs:233)

  • What happens: the deferred estimate already trial-compresses the sample, then compress() repeats it.
  • Cost: the trial bit-packs v2, v1, and the BitPacked baseline, and compresses the references. For arrays of at most 9 blocks the "sample" is the whole array.
  • Why it is safe to skip: the sample is deterministic (SAMPLE_SEED), so the second call always returns the same answer.
  • Suggested fix: pass the estimate's v2-or-v1 decision through to compress() instead of recomputing it.

3. CodSpeed regressions are not explained

  • Encode: encode_chunked[i64] is 37% slower on AVX2 and 15–22% slower in the nullable and NEON variants.
  • Decode: decode_chunked[i64] is 10% slower on AVX2 and AVX-512.
  • Decode cause: the bench's doc comment (for_decode.rs:107) says references are "added in place instead of into a copy". With a u8 child that is no longer true, because decode allocates a new i64 buffer. The bench now measures something other than what it describes. Either update the comment or keep an un-narrowed variant.
  • Encode cause: the regression probably comes from the per-element narrowing cast in subtract_*_narrow. It should be fixed or acknowledged.

4. No benchmark backs the headline speedups (carried over)

  • The PR description claims compare is 11x–100x faster and decode up to 2.2x faster, but no benchmark for blocked compare, filter, or take lands with it.
  • AGENTS.md asks for the benchmark to land first so CodSpeed has a baseline.

5. The wire contract changes without a new ID (carried over, lower priority)

  • What changed: encoded_bytes (tag 2) is new under the existing fastlanes.for.v2 ID.
  • What the new test covers: a new reader decoding old data.
  • What it does not cover: a reader built before this PR still misreads a narrowed child silently instead of failing.
  • Why the risk is small: fastlanes.for.v2 is first declared in UNSTABLE here.
  • What to do: accepting the risk is reasonable, but the PR description should say so.

Smaller notes

  • Duplicated code: the filter and take paths still repeat the same loops for the same-width and narrowed cases, and the patch fixup is written several times. One generic over U: AsPrimitive<T> would cover them, and it could follow in a later PR.
  • Untested selector constants: the selector's tuned constants (MIN_V2_*, EIGHT_BIT_ACCESS_COST_FACTOR, PATCH_DENSITY_COST_BITS) still have no corpus test in the repo. The ablation table in the PR comment is the only evidence.

I could not run any builds or tests in this read-only workflow. Everything above comes from reading the code.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@lwwmanning
lwwmanning marked this pull request as draft November 25, 2026 02:32
@lwwmanning
lwwmanning marked this pull request as ready for review November 25, 2026 03:52
chatgpt-codex-connector[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
…encode

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>

@vortex-roborev-bot vortex-roborev-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line comments for the roborev review of 37e848c. The roborev PR comment has the full review.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
…ned max

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>

@vortex-roborev-bot vortex-roborev-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line comments for the roborev review of b4140b1. The roborev PR comment has the full review.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

I reviewed f2cf13a with fresh eyes. The blocked compare, filter, take, is_constant and is_sorted kernels look correct, and check_blocked_kernels compares every kernel against the decoded array across wrap, nulls, patches and slices. Points:

  1. The wide-span fallback can leave a column uncompressed. At schemes/integer/for_.rs:266, when an unsampled block of a signed column spans more than T::MAX, encode returns Encoded::leaf(data.array().clone()). The cascade's size check then rejects the output and returns Selection::unchanged, so the runner-up scheme (Dict, or ZigZag plus BitPacking) is never tried. The codex thread raised this and Devin's fix delegated to compress_child, but a later fix replaced that with the leaf return, so the problem is back. test_v2_handles_wide_span_inside_block uses for_only(), so it cannot show it.
  2. FoRPacked::decode_chunk (for_/compute/mod.rs:190) calls assume_init_mut() on uninitialized slots and passes them as &mut [T]. The std docs call that undefined behaviour. unfor_pack_into has the same pattern, so one decision for both sites would be good, for example writing through MaybeUninit pointers.
  3. apply_patches now runs patches.values().all_valid(ctx) on the lazy array and then executes patches.values() again in for_each_decoded_patch. Before, the check ran once on the executed values.

The selector's tuned constants still have no tests of their own.

Signed-off-by: Will Manning <will@spiraldb.com>
… avoid double patch execution

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed all three points in 95ae0f3de:

  1. Wide-span fallback (vortex-btrblocks/src/schemes/integer/for_.rs): when has_negative_residuals or BitPackingScheme::try_encode declines, FoRScheme::encode now delegates back to the cascade via Child::new(self, 0, data.array().clone()) (self-excluding FoR via cascade history) so runner-up schemes such as Dict or ZigZag+BitPacking compress the column. Extended test_v2_handles_wide_span_inside_block to verify compression with IntDictScheme present.
  2. MaybeUninit UB (for_decompress.rs & for_/compute/mod.rs): both unfor_pack_into and FoRPacked::decode_chunk now share unfor_pack_into, which unpacks via BitPacking::unchecked_unpack_uninit into &mut [MaybeUninit<T>] and adds the reference after initialization instead of transmuting/calling assume_init_mut() on uninitialized slots.
  3. Duplicate patches.values() check (for_decompress.rs): moved assert!(values.as_ref().all_valid(ctx)?) into for_each_decoded_patch on the already-executed PrimitiveArray and dropped the redundant check on the lazy array in apply_patches.

(Tuned selector constants stay unchanged per Will's earlier decision.)

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

I reviewed 95ae0f3. The wide-span fallback now hands the input to the cascade as a child, and self-exclusion stops FoR from being picked again, so the runner-up scheme gets its chance. The double patch execution is gone. The MaybeUninit fix is sound, but it is expensive:

CodSpeed shows large slowdowns on this head that were not there on f2cf13a. dictionary_export[chunked/nonnull] goes from 187.2 µs to 984.3 µs and dictionary_export[chunked/nullable] from 232.5 µs to 1,103.6 µs, about 5 times slower. decode_bitpacked_chunked_* at 524,288 rows are 12 to 27% slower in walltime. unfor_pack_into now unpacks with unchecked_unpack_uninit and adds the reference in a second pass, so the main decompress path (unpack_chunks) loses the fused FFoR kernel, not only decode_chunk. fastlanes 0.8.3 has no fused unpack-and-add into uninitialized memory. Options I can see: add one to fastlanes, run the fused kernel per 1,024-value chunk into a stack buffer and copy out, or keep the old fused path in unfor_pack_into and fix only the new decode_chunk site. Whichever you choose, the regression should not land with this PR.

Nits on the new tests: for_config.rs:292 checks only that the output is smaller than the input, so it does not show that FoR won selection and then fell back, rather than IntDict winning outright. The closure in for_.rs is duplicated at both fallback sites.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>

# Conflicts:
#	vortex-btrblocks/src/schemes/integer/for_.rs
#	vortex-compressor/src/compressor/mod.rs
Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed in 09330c190..6b77bce73:

  • Fused unfor_pack_into restored: restored encodings/fastlanes/src/for_/array/for_decompress.rs's unfor_pack_into to develop's fused T::unchecked_unfor_pack path so unpack_chunks / dictionary_export / decode_bitpacked_chunked_* keep the fused FFoR kernel, while keeping the new FoRPacked::decode_chunk filter path sound via T::Physical::unchecked_unpack_uninit + wrapping add.
  • Fallback helper & test: extracted delegate_to_cascade in vortex-btrblocks/src/schemes/integer/for_.rs to remove the duplicated closure, and wrapped IntDictScheme in a fixed-1.5x LowBidDict in test_v2_handles_wide_span_inside_block (vortex-btrblocks/tests/for_config.rs) so FoR (~10x on the sampled narrow chunks) is guaranteed to win selection first and only falls back to LowBidDict via cascade delegation.

@vortex-roborev-bot vortex-roborev-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line comments for the roborev review of 6b77bce. The roborev PR comment has the full review.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
Signed-off-by: Will Manning <will@spiraldb.com>

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

I reviewed the whole PR at 426901d with fresh eyes. The blocked filter, take, compare, is_constant and is_sorted kernels look correct, CI and CodSpeed pass, and the dictionary_export slowdown is gone. My points are about size and tests. The PR adds about 1,830 lines of non-test code, and I think a few hundred of them can go.

  1. The selector in schemes/integer/for_.rs runs its own contest in about 370 lines. evaluate_v2_on_sample trial-compresses BitPacked, FoR v1 and RunEnd on the 8x1,024 sample to build a baseline. It then applies five tuned constants. They are 5%, 0.4 bits per value, a 1.05 ratio floor, a 1.12 factor for 1-byte types and a 320-bit patch-density cost. No test pins any of the five.

    Please say which of them changed the result on the 110-column corpus, and drop the others. Each one you keep should have a test that fails without it.

  2. The filter and take paths repeat each loop twice. filter_blocked_primitive and filter_blocked_alloc hold the same slice walk and the same set-index walk, and take_blocked_typed and take_blocked_alloc repeat the take loop. They differ only in whether the code reuses the buffer or copies it first. One version that copies a shared buffer into a BufferMut and then runs one loop would remove about 80 lines.

  3. Most of check_blocked_kernels in for_/tests.rs repeats check_encoding_roundtrip_and_ops from vortex_array::compute::conformance::hegel. That harness already checks compare against a constant and chained slice, take, filter and mask. It also adds a serialize and decode round trip of fastlanes.for.v2, which no property test covers today. Please call the harness from fused_decode_is_wrapping_add and keep only the is_constant and is_sorted asserts. This needs the _test-harness-hegel feature on the vortex-array dev-dependency.

    Hand-written cases that the property then covers, such as test_blocked_filter_and_take_multi_chunk_patched_sliced, can go. Keep the galloping and copy-path tests, because the property does not reach them.

…arness

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed points 2 and 3 in 60e87c137 (-224 net lines):

  1. Selector constants (schemes/integer/for_.rs): left unchanged per Will's earlier decision on this PR to keep the five tuned selector constants as-is without adding tests for them.
  2. Deduplicated filter/take loops (encodings/fastlanes/src/for_/compute/mod.rs): filter_blocked_primitive and take_blocked_typed now copy a shared buffer into a BufferMut via ctx.allocator() and run a single loop, removing filter_blocked_alloc and take_blocked_alloc.
  3. Hegel conformance harness (encodings/fastlanes/src/for_/tests.rs, encodings/fastlanes/Cargo.toml): enabled _test-harness-hegel on vortex-array dev-dependencies, replaced check_blocked_kernels in fused_decode_is_wrapping_add with check_encoding_roundtrip_and_ops (which also covers fastlanes.for.v2 serde roundtrip and chained ops) plus is_constant/is_sorted/is_strict_sorted checks, and dropped test_blocked_filter_and_take_multi_chunk_patched_sliced while keeping the galloping and shared-buffer copy tests.

@vortex-roborev-bot vortex-roborev-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line comments for the roborev review of 60e87c1. The roborev PR comment has the full review.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

I reviewed 693be5b, and it fixes the roborev finding correctly. At the last cascade depth, V2 mode no longer returns Skip. Both expected_compression_ratio and encode now keep single-reference FoR.v1 when finished_cascading() is true. FoR.v1 has no child to compress. The two checks match, so the estimate and the encode cannot disagree.

The updated test checks that the result is FoR with no blocked references. It also checks that the result is under a quarter of the input size and round-trips.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
This reverts commit 1003e8b.

Signed-off-by: Will Manning <will@spiraldb.com>

This branch has not been deployed

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

Labels

changelog/feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking Issue: Finish blocked FoR (fastlanes.for.v2) selector, residual narrowing, and kernels

2 participants