Skip to content

perf(fastlanes): push FoR ordering comparisons to the encoded values - #10147

Merged
robert3005 merged 5 commits into
developfrom
rk/for-compare-ordering
Nov 4, 2026
Merged

robert3005 merged 5 commits into
developfrom
rk/for-compare-ordering

Conversation

@robert3005

Copy link
Copy Markdown
Contributor

FoR only compared for equality, so ordering comparisons decoded the array, which also bypassed the bit-packed child's own compare kernel. Encoding subtracts the minimum, so the encoded values are non-negative distances. For unsigned types the kernel compares them against the constant's distance directly; for signed types it does so when the child is bit-packed, which keeps the distances non-negative in the signed reading, and otherwise falls back to decoding. A distance that does not fit the type answers by which side of the reference the constant lies on.

@robert3005 robert3005 added the changelog/performance A performance improvement label Sep 30, 2026
@codspeed

codspeed Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 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

✅ 1765 untouched benchmarks
⏩ 130 skipped benchmarks1


Comparing rk/for-compare-ordering (7e32591) with develop (8b01ab5)

Open in CodSpeed

Footnotes

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

@github-actions

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 Oct 16, 2026
@mightsleep

Copy link
Copy Markdown
Contributor

Yes hello,
re your note about asking for a min: I think nothing needs to be asked for. An interval is an arc on Z/2^T and FoR decoding is a rotation, so v in [lo, hi] iff (e - (lo - ref)) mod 2^T <= hi - lo, for every encoded e and in either signed or unsigned order (the sign bias cancels in the difference). Lt/Lte/Gt/Gte are arcs with one end at the type bound, so this needs no min of the encoded values, no signed fallback and no overflow branch. FoR between currently decodes the whole column (no BetweenKernel), and the same arc gives it one offset compare on the bit-packed child. Happy to fold the ordering compares into a FoR between PR on top of #10559 if you'd rather close this one, or leave them here if you want to keep it.

@github-actions github-actions Bot removed the stale This PR is stale and will be auto-closed soon label Oct 21, 2026
@robert3005
robert3005 force-pushed the rk/for-compare-ordering branch from 1f2a36a to 41003b0 Compare October 21, 2026 22:06
@robert3005
robert3005 requested a review from mhk197 October 29, 2026 11:02
@robert3005
robert3005 force-pushed the rk/for-compare-ordering branch from 41003b0 to 2cfa43a Compare October 29, 2026 12:07
@robert3005
robert3005 requested a review from mhk197 October 29, 2026 12:07
@robert3005
robert3005 force-pushed the rk/for-compare-ordering branch 2 times, most recently from 9615f8b to 11cd5c3 Compare October 29, 2026 13:10
@robert3005
robert3005 enabled auto-merge (squash) October 29, 2026 13:10
FoR only compared for equality, so ordering comparisons decoded the
array, which also bypassed the bit-packed child's own kernels.

The reference must be at most every valid value, which the encoders
guarantee by using the minimum. Each encoded value then holds the exact
distance from the reference, read as unsigned. For unsigned types the
kernel compares the encoded values against the constant's distance.
For signed types, distances above the type's maximum read as negative,
so each operator becomes one between on the encoded values, or its
negation. This needs no statistics and keeps a bit-packed child packed.
A constant below the reference answers with a constant result.

Tests build FoR over bit-packed children with signed, unsigned, and
nullable values, and over an i8 child that spans the full range, and
compare every operator against the primitive baseline.

Signed-off-by: Robert Kruszewski <github@robertk.io>
A constant below the reference answers every row without the encoded
values. The answer took only the nullability of the constant, so a
nullable array compared to a non-nullable constant gave a non-nullable
result, and an all-null array panicked when it made a null scalar.

Join the nullability of the array with the nullability of the constant,
and test the all-valid, all-invalid and array validities.

Signed-off-by: Robert Kruszewski <github@robertk.io>
@robert3005
robert3005 force-pushed the rk/for-compare-ordering branch from f27a0c4 to 067cdf7 Compare November 2, 2026 17:33
Replace the `NativePType + PrimInt` bounds with `IntegerPType` and make the
`FoRData` reference invariant easier to read.

Signed-off-by: Robert Kruszewski <github@robertk.io>
Answer Eq and NotEq with a constant when the constant is below the
reference. Rename compare_encoded to compare_unsigned_encoded, bound it
on IntegerPType and document it. Move strictness into
compare_signed_encoded.

Signed-off-by: Robert Kruszewski <github@robertk.io>
@robert3005
robert3005 force-pushed the rk/for-compare-ordering branch from 6039243 to 6ebdf4e Compare November 4, 2026 16:14
Signed-off-by: Robert Kruszewski <github@robertk.io>
@robert3005
robert3005 merged commit 141abdc into develop Nov 4, 2026
70 checks passed
@robert3005
robert3005 deleted the rk/for-compare-ordering branch November 4, 2026 16:39
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.

4 participants