Skip to content

bench(arrow-ipc): add lz4 compression benchmarks for IPC writer - #12083

Merged
Rich-T-kid merged 1 commit into
apache:mainfrom
gabotechs:ipc-lz4-benches
Nov 5, 2026
Merged

Rich-T-kid merged 1 commit into
apache:mainfrom
gabotechs:ipc-lz4-benches

Conversation

@gabotechs

@gabotechs gabotechs commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Adds some new benches for helping qualify a future change in #12084.

The new benchmarks are some StreamWriter/StreamEncoder cases using CompressionType::LZ4_FRAME, including single-threaded and multi-threaded (contended) variants.

@github-actions github-actions Bot added parquet parquet crate arrow-ipc arrow-ipc crate arrow-kernels Crates that transform arrow data (e.g. compute, cast) labels Nov 5, 2026
@gabotechs
gabotechs force-pushed the ipc-lz4-benches branch 2 times, most recently from 94b5782 to 3c63870 Compare November 5, 2026 06:55
@github-actions github-actions Bot removed parquet parquet crate arrow-kernels Crates that transform arrow data (e.g. compute, cast) labels Nov 5, 2026
Adds single-threaded and multi-threaded StreamWriter/StreamEncoder
benchmark cases using LZ4_FRAME compression, to establish a baseline
for upcoming lz4 encoder optimizations.

@Rich-T-kid Rich-T-kid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

makes sense, left a comment

Comment on lines +89 to +102
b.iter(|| {
std::thread::scope(|s| {
for _ in 0..threads {
s.spawn(|| {
let options = IpcWriteOptions::default()
.try_with_compression(Some(CompressionType::LZ4_FRAME))
.unwrap();
let mut encoder = StreamEncoder::try_new_with_options(
batch.schema().as_ref(),
options,
)
.unwrap();
for _ in 0..10 {
black_box(encoder.encode(&batch).unwrap());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we need to spawn threads here? I'm confused on what extra insight this gives us over a single thread

@gabotechs gabotechs Nov 5, 2026 •

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.

Single thread just measures raw compression speed. The threads=16 cases are there to catch contention that only shows up when multiple encoders run at once, e.g. allocator pressure from each one setting up its own buffers. Without concurrent cases, that kind of regression (or improvement) would be invisible in these benchmarks.

My guess that different threads will start competing for big allocations through a single global allocator doing syscalls, but it's just a guess, the main reason for me to include the multithreaded cases is because I have empirically tested that the biggest performance improvements happen there.

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.

During benchmarks in #12084, the multithreaded cases are the ones that show the biggest improvements

@Rich-T-kid Rich-T-kid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks @gabotechs

@Rich-T-kid
Rich-T-kid added this pull request to the merge queue Nov 5, 2026
Merged via the queue into apache:main with commit 3ac3836 Nov 5, 2026
23 checks passed
@Jefffrey Jefffrey added the development-process Internal changes; PRs with this label are excluded from changelog label Nov 5, 2026
Rich-T-kid added a commit to Rich-T-kid/arrow-rs that referenced this pull request Nov 6, 2026
…pache#12084)

Something that showed up during some profiling of a downstream project
that depends on `arrow-rs`, hopefully the benchmarks in
apache#12083 can be used for helping
qualify this change (review that PR first)

- Caches the `lz4_flex` `FrameEncoder` (hash table + block buffers) in
`IpcWriteContext` and reuses it across `compress_lz4` calls instead of
allocating a fresh encoder per buffer, mirroring the existing zstd
context reuse.
- Pins the frame's block size to 256KB so a reused encoder's block size
isn't fixed by the first buffer it ever wrote.
- On error mid-frame, drops the cached encoder so the next call starts
fresh.

## Benchmark results

Measured on a 16-core macOS machine, comparing the base of this stack
(apache#12083, no encoder reuse) against this PR:

`cargo bench -p arrow-ipc --bench ipc_writer --features lz4,zstd -- lz4`

| Case | Criterion |
|---|---|
| `StreamWriter/write_10/lz4` | -1.7% |
| 8,192 rows, 1 thread | -1.7% |
| 65,536 rows, 1 thread | +1.0% |
| 8,192 rows, 16 threads | **-19.5%** |
| 65,536 rows, 16 threads | -6.3% |

---------

Co-authored-by: RIchard Baah <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-ipc arrow-ipc crate development-process Internal changes; PRs with this label are excluded from changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants