Skip to content

perf(encoding): avoid inline bitpacking input copy#7748

Closed
u70b3 wants to merge 1 commit into
lance-format:mainfrom
u70b3:perf/inline-bitpack-unchunk-combined
Closed

perf(encoding): avoid inline bitpacking input copy#7748
u70b3 wants to merge 1 commit into
lance-format:mainfrom
u70b3:perf/inline-bitpack-unchunk-combined

Conversation

@u70b3

@u70b3 u70b3 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Supersedes #7696. This PR contains the same changes as #7696, but squashed into a single commit with a consolidated commit message.

Summary

  • Avoid the unconditional input copy in InlineBitpacking::unchunk by borrowing a typed view over the inline bitpacking chunk words.
  • Keep output zero-initialization unchanged; this PR only changes compressed input handling.
  • Add focused unchunk roundtrip coverage and a Criterion benchmark comparing the old copy path with the new typed-view path.
  • Harden validation by rejecting malformed inline bitpacking chunks up front with clear errors.

Benchmark

Local machine: WSL2 on Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz, 12 logical CPUs.

Command:

cargo bench -p lance-encoding --bench decoder decode_inline_bitpacking_unchunk --features bitpacking -- --noplot

Results:

Case Path Criterion time estimate Throughput
u32_bw12_1024 legacy_copy 285.46 ns 5.0244 GiB/s
u32_bw12_1024 typed_view 247.35 ns 5.7985 GiB/s
u64_bw23_1024 legacy_copy 434.11 ns 6.3331 GiB/s
u64_bw23_1024 typed_view 340.27 ns 8.0797 GiB/s

Path-to-path deltas:

  • u32_bw12_1024: typed_view was 13.4% faster than legacy_copy
  • u64_bw23_1024: typed_view was 21.6% faster than legacy_copy

The benchmark uses aligned chunks built with LanceBuffer::reinterpret_vec, so it measures the aligned borrow_to_typed_view fast path. Misaligned buffers can still fall back to a copy.

Test Plan

  • cargo fmt --all
  • cargo test -p lance-encoding --features bitpacking
  • cargo clippy -p lance-encoding --all-features --tests --benches -- -D warnings
  • cargo clippy --all --tests --benches -- -D warnings
  • cargo bench -p lance-encoding --bench decoder decode_inline_bitpacking_unchunk --features bitpacking -- --noplot

Summary by CodeRabbit

  • Bug Fixes

    • Improved inline bitpacked data decoding with stronger validation for malformed buffers, invalid value counts, unsupported bit widths, alignment issues, and inconsistent payload sizes.
    • Added clearer corruption errors to help identify invalid encoded data.
  • Performance

    • Improved the inline bitpacking decoding path by using typed views, reducing unnecessary data copying.
  • Tests

    • Expanded coverage for valid round trips, corruption handling, and decoding performance across multiple data types and bit widths.

Replace the unconditional input copy in `InlineBitpacking::unchunk` with a
typed view borrowed over the inline bitpacking chunk words. Output buffers
continue to be zero-initialized before decoding.

Also:
- Validate chunk headers up front and reject malformed inline bitpacking
  chunks with clear errors.
- Expand `unchunk` roundtrip and corruption tests to cover header sizing,
  alignment, payload length mismatches, invalid bit widths, and excessive
  value counts.
- Initialize bitpacking output with Default.

Local benchmark (WSL2, i7-10700, `cargo bench -p lance-encoding --bench
decoder decode_inline_bitpacking_unchunk --features bitpacking -- --noplot`):

| Case          | Path        | Time    | Throughput   |
|---------------|-------------|--------:|-------------:|
| u32_bw12_1024 | legacy_copy | 285 ns  | 5.0 GiB/s    |
| u32_bw12_1024 | typed_view  | 247 ns  | 5.8 GiB/s    |
| u64_bw23_1024 | legacy_copy | 434 ns  | 6.3 GiB/s    |
| u64_bw23_1024 | typed_view  | 340 ns  | 8.1 GiB/s    |

typed_view is ~13% faster for u32_bw12_1024 and ~22% faster for
u64_bw23_1024.
@github-actions github-actions Bot added A-python Python bindings A-java Java bindings + JNI A-deps Dependency updates A-encoding Encoding, IO, file reader/writer performance labels Jul 13, 2026
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bbe1224b-71d5-465b-bb02-c4f24f4a5672

📥 Commits

Reviewing files that changed from the base of the PR and between 787f759 and d61b50f.

⛔ Files ignored due to path filters (3)
  • Cargo.lock is excluded by !**/*.lock
  • java/lance-jni/Cargo.lock is excluded by !**/*.lock
  • python/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • rust/lance-encoding/Cargo.toml
  • rust/lance-encoding/benches/decoder.rs
  • rust/lance-encoding/src/encodings/physical/bitpacking.rs

📝 Walkthrough

Walkthrough

Inline bitpacking unchunking now uses typed header/payload views with explicit validation and structured corruption errors. Tests cover valid and invalid inputs, while Criterion benchmarks compare legacy copying with typed-view decoding.

Changes

Inline bitpacking decoding

Layer / File(s) Summary
Typed unchunk validation
rust/lance-encoding/Cargo.toml, rust/lance-encoding/src/encodings/physical/bitpacking.rs
Adds the workspace dependency and rewrites inline unchunking around typed views, payload-size checks, bounds validation, and structured corruption errors.
Unchunk round-trip and corruption tests
rust/lance-encoding/src/encodings/physical/bitpacking.rs
Adds round-trip coverage for selected bit widths and parameterized checks for malformed headers, alignment, value counts, payload sizes, and bit widths.
Legacy and typed-view benchmarks
rust/lance-encoding/benches/decoder.rs
Adds feature-gated benchmarks that generate inline chunks and compare legacy-copy decoding with InlineBitpacking typed-view decoding. Targets are registered on Linux and non-Linux builds.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Criterion
  participant ChunkGenerator
  participant LegacyDecoder
  participant InlineBitpacking
  Criterion->>ChunkGenerator: generate inline bitpacked chunk
  Criterion->>LegacyDecoder: decode with legacy_copy
  Criterion->>InlineBitpacking: decode with typed_view
  LegacyDecoder-->>Criterion: return decoded payload
  InlineBitpacking-->>Criterion: return decoded payload
  Criterion->>Criterion: compare decoded buffers and record timings
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: optimizing inline bitpacking to avoid copying input.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.31818% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ance-encoding/src/encodings/physical/bitpacking.rs 94.31% 3 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@u70b3

u70b3 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Closed: changes will be force-pushed to the original branch #7696 as a single commit.

@u70b3 u70b3 closed this Jul 13, 2026
@u70b3
u70b3 deleted the perf/inline-bitpack-unchunk-combined branch July 16, 2026 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-deps Dependency updates A-encoding Encoding, IO, file reader/writer A-java Java bindings + JNI A-python Python bindings performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant