Skip to content

Compute integer statistics in one hand-written pass per need - #10346

Merged
robert3005 merged 2 commits into
developfrom
ji/int-stats-kernels
Nov 11, 2026
Merged

robert3005 merged 2 commits into
developfrom
ji/int-stats-kernels

Conversation

@joseph-isaacs

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

Copy link
Copy Markdown
Contributor

Summary

Computes the integer compression statistics in one hand-written pass per need. Only vortex-compressor/src/stats/integer.rs changes, and every statistic has the same value as before.

  • Validity is read one u64 per chunk of 64 values. For the runs, nulls are filled with the previous valid value. When only the bounds are needed, values of at most 32 bits read nulls as the identity instead, with a branch-free select.
  • Min and max are folded with lane accumulators in the same pass as the runs. This replaces the separate min_max aggregate. The bounds and the null count are cached on the array, and bounds already cached there are reused.
  • The distinct counter (none, dense or hashed) is chosen once, and the pass is monomorphized on it. When min equals max, counting is skipped.
  • The lane count depends on the type width and the instruction set. Without AVX2, 32-bit values use 32 lanes.

The tests compare min, max, runs and distinct counts against a naive reference for u8, i16, u32, i64 and u64.

Benchmark

integer_stats, 64Ki u32, median µs:

develop (M4) this PR (M4) CodSpeed (x86)
non_null 7.4 6.5 1.2×
nullable 48.7 13.7 3.2×
all_non_null 63–81 58–79 1.5×
all_nullable 99–145 46–53 2.6×

On M4, u8, u16 and u64 with nulls are 2–4× faster. Without nulls, distinct counting is slower than develop (u8 40 → 56 µs, u64 49 → 68 µs), and so are u64 statistics without distinct counting (17 → 24 µs). integer_stats covers only u32.

🤖 Generated with Claude Code

@joseph-isaacs joseph-isaacs added the changelog/performance A performance improvement label Oct 6, 2026 — with Claude
@codspeed

codspeed Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by ×2

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

⚡ 4 improved benchmarks
✅ 1917 untouched benchmarks
⏩ 50 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation integer_stats_nullable 1,794 µs 550.3 µs ×3.3
⚡ CPU Simulation integer_stats_all_nullable 2,430.4 µs 926 µs ×2.6
⚡ CPU Simulation integer_stats_all_non_null 1,186.8 µs 757.9 µs +56.6%
⚡ CPU Simulation integer_stats_non_null 393.1 µs 327.8 µs +19.92%

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/int-stats-kernels (e234151) with develop (b2d08cc)

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
joseph-isaacs changed the base branch from ji/int-stats-null-words to ji/int-stats-all-bench October 6, 2026 20:03
@codecov

codecov Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.29060% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.28%. Comparing base (69a3b50) to head (477507c).

Files with missing lines Patch % Lines
vortex-compressor/src/stats/integer.rs 98.29% 6 Missing ⚠️

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joseph-isaacs
joseph-isaacs added this pull request to stack #10351 October 7, 2026 09:57
Base automatically changed from ji/int-stats-all-bench to develop October 7, 2026 10:01
@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 26, 2026
@joseph-isaacs joseph-isaacs removed the stale This PR is stale and will be auto-closed soon label Oct 26, 2026 — with Claude
@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 Nov 11, 2026
@joseph-isaacs joseph-isaacs removed the stale This PR is stale and will be auto-closed soon label Nov 11, 2026 — with Claude
joseph-isaacs and others added 2 commits November 11, 2026 10:38
Read the validity a word per chunk of 64 values instead of slicing a bit
buffer per chunk, and fill each null with the valid value before it, so
that the bounds and the runs take the vectorized kernel of non-null
chunks. Distinct counting visits only the set bits.

Compute min/max with lane accumulators in the same pass as the runs, or
as the distinct counts for bytes, instead of a separate min_max
aggregate over each valid range. Write the bounds and the null count
back to the array statistics, as the aggregate did, and reuse cached
bounds. Wider types counting distinct values still compute the bounds
first, in their own pass, to choose a counter.

Choose the distinct counter once and monomorphize the pass on it, and
keep the run state in locals so that count updates cannot alias it.
Skip counting when the bounds show every valid value is the same.

Fold the lanes behind a reference in a function of their own: as locals
of the large caller, the vectorizer left them scalar. Choose the lane
count per instruction set: with AVX2, 32-bit bounds fold over a whole
chunk and 64-bit bounds over 8 lanes.

Tidy the integer stats scan:

Give the lane bounds their own constructor and reduction, convert the
dense counter's bounds to i128 once, name the empty distinct info, and
make the chunk accumulator's control flow explicit instead of returning
early. Callgrind shows no regression on any type with or without AVX2;
u8 and u16 distinct counting runs about 6% fewer instructions.

Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
Signed-off-by: Robert Kruszewski <github@robertk.io>
…lone

Without AVX2, 32-bit bounds fold over 32 lanes instead of 16. On an Apple
M4, 16 lanes made the non-null stats of u32 twice as slow as develop.

Where the runs do not need the nulls filled, which is the bounds pass
before distinct counting and the counting pass of bytes, values of at
most 32 bits read each null as the identity of each bound instead of
filling it. The select is a mask of all ones or all zeros: as an `if`,
LLVM branches on each validity bit and leaves the lanes scalar. 64-bit
values keep the fill, which is cheaper with their few lanes.

integer_stats, 64Ki u32, Apple M4, median µs:

|                | develop | before | after |
|----------------|--------:|-------:|------:|
| non_null       |     7.4 |   16.1 |   6.5 |
| nullable       |    48.7 |   22.6 |  13.7 |
| all_non_null   |   63-81 |  72-81 | 72-79 |
| all_nullable   |  99-145 |  58-73 | 46-49 |

Signed-off-by: Robert Kruszewski <github@robertk.io>
@robert3005
robert3005 merged commit e9e55db into develop Nov 11, 2026
76 checks passed
@robert3005
robert3005 deleted the ji/int-stats-kernels branch November 11, 2026 13:57
robert3005 added a commit that referenced this pull request Nov 16, 2026
…sk_word

Add `for_each_mask_word` and `try_for_each_mask_word` to `vortex-compute`.
They walk a `BitBufferView` one `u64` word at a time through
`unaligned_chunks`, so the 8-byte aligned body is read with no reshift for
each word.

Use the walk in these places instead of a local copy:

- the masked lane kernels `map_masked_into`, `try_map_masked_into` and
  `try_map_masked_in_place`, which now accept `impl Into<BitBufferView>`
- the filter word walk for a mask bitmap
- the primitive and ListView zip kernels
- the FoR encoder for chunks with mixed validity, which no longer copies
  the validity words into a `Vec`

Compute the float statistics over chunks of 64 values. A chunk that is
fully valid has a branch-free count of its runs, and a mixed chunk
gathers its valid values first.

The integer statistics are not changed. #10346 rewrote them on develop
and that replaces the changes this branch made to them.

Signed-off-by: Robert Kruszewski <github@robertk.io>
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.

2 participants