Repository navigation
bench(arrow-ipc): add lz4 compression benchmarks for IPC writer - #12083
Conversation
94b5782 to
3c63870
Compare
Adds single-threaded and multi-threaded StreamWriter/StreamEncoder benchmark cases using LZ4_FRAME compression, to establish a baseline for upcoming lz4 encoder optimizations.
3c63870 to
1c7e196
Compare
Rich-T-kid
left a comment
There was a problem hiding this comment.
makes sense, left a comment
| 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()); |
There was a problem hiding this comment.
why do we need to spawn threads here? I'm confused on what extra insight this gives us over a single thread
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
During benchmarks in #12084, the multithreaded cases are the ones that show the biggest improvements
…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]>
Adds some new benches for helping qualify a future change in #12084.
The new benchmarks are some
StreamWriter/StreamEncodercases usingCompressionType::LZ4_FRAME, including single-threaded and multi-threaded (contended) variants.