Skip to content

perf(arrow-ipc): reuse lz4 frame encoder buffers across IPC writes - #12084

Merged
Rich-T-kid merged 5 commits into
apache:mainfrom
gabotechs:ipc-lz4-reuse-frame-buffers
Nov 6, 2026
Merged

Rich-T-kid merged 5 commits into
apache:mainfrom
gabotechs:ipc-lz4-reuse-frame-buffers

Conversation

@gabotechs

@gabotechs gabotechs commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Something that showed up during some profiling of a downstream project that depends on arrow-rs, hopefully the benchmarks in #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 (#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%

@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-reuse-frame-buffers branch 2 times, most recently from 47e6d6f to 29cc3dd 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.
@gabotechs
gabotechs force-pushed the ipc-lz4-reuse-frame-buffers branch from 29cc3dd to add5d56 Compare November 5, 2026 13:37
Caches the lz4_flex FrameEncoder (including its hash table and block
buffers) in IpcWriteContext and reuses it across compress_lz4 calls,
instead of allocating a fresh encoder per buffer. The block size is
pinned to 256KB so a reused encoder's block size is not fixed by the
first buffer written. Mirrors the existing zstd context reuse.
@gabotechs
gabotechs force-pushed the ipc-lz4-reuse-frame-buffers branch from add5d56 to 6bc9994 Compare November 5, 2026 13:41
@Rich-T-kid

Copy link
Copy Markdown
Contributor

will merge up and run the benchmarks when the benchmarks are merged

Rich-T-kid pushed a commit to gabotechs/arrow-rs that referenced this pull request Nov 5, 2026
…he#12083)

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

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

Copy link
Copy Markdown
Contributor

run benchmark ipc_writer
env:
BENCH_FILTER: StreamEncoder/encode_10/lz4/

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: ipc_writer

Sharding factor: 1 (1 workers).

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4/
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@Rich-T-kid

Copy link
Copy Markdown
Contributor

run benchmark ipc_writer
env:
BENCH_FILTER: StreamEncoder/encode_10/lz4/

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: ipc_writer

Sharding factor: 1 (1 workers).

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4/
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: ipc_writer

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4/
shards: 1
Details
group                                                                        base                                   changed
-----                                                                        ----                                   -------
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=1     1.45     35.6±0.64ms        ? ?/sec    1.00     24.5±0.33ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=16    1.71     53.1±5.43ms        ? ?/sec    1.00     31.0±2.97ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=1      1.02      2.9±0.02ms        ? ?/sec    1.00      2.8±0.02ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=16     1.02      3.8±0.42ms        ? ?/sec    1.00      3.8±0.41ms        ? ?/sec

Per-runner information
ipc_writer — shard 1/1

Node: gk3-benchmark-cluster-nap-1ghb8pp5-d2cf91a9-x967

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c6663530801-4523-mcr9w 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench ipc_writer
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 45.0s
Peak memory 95.1 MiB
Avg memory 27.4 MiB
CPU user 181.3s
CPU sys 47.5s
Peak spill 0 B

branch

Metric Value
Wall time 45.0s
Peak memory 77.1 MiB
Avg memory 30.7 MiB
CPU user 236.2s
CPU sys 2.9s
Peak spill 0 B

File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: ipc_writer

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4/
shards: 1
Details
group                                                                        base                                   changed
-----                                                                        ----                                   -------
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=1     1.50     36.2±0.56ms        ? ?/sec    1.00     24.1±0.08ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=16    1.72     53.5±5.89ms        ? ?/sec    1.00     31.2±3.03ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=1      1.03      2.9±0.02ms        ? ?/sec    1.00      2.8±0.02ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=16     1.02      3.8±0.58ms        ? ?/sec    1.00      3.8±0.48ms        ? ?/sec

Per-runner information
ipc_writer — shard 1/1

Node: gk3-benchmark-cluster-nap-1ghb8pp5-d2cf91a9-6t9b

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c6663528751-4522-p4r25 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench ipc_writer
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 45.0s
Peak memory 90.3 MiB
Avg memory 29.7 MiB
CPU user 180.3s
CPU sys 47.2s
Peak spill 0 B

branch

Metric Value
Wall time 45.0s
Peak memory 82.8 MiB
Avg memory 32.5 MiB
CPU user 241.2s
CPU sys 3.6s
Peak spill 0 B

File an issue against this benchmark runner

@Rich-T-kid

Copy link
Copy Markdown
Contributor

run benchmark ipc_writer
env:
BENCH_FILTER: StreamEncoder/encode_10/lz4
resources:
cpu: "4"

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: ipc_writer

Sharding factor: 1 (1 workers).

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4
resources:
  cpu: '4'
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@Rich-T-kid

Copy link
Copy Markdown
Contributor

run benchmark ipc_writer
env:
BENCH_FILTER: StreamEncoder/encode_10/lz4/ro
resources:
cpu: "8"

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: ipc_writer

Sharding factor: 1 (1 workers).

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4/ro
resources:
  cpu: '8'
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: ipc_writer

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4/ro
resources:
  cpu: '8'
shards: 1
Details
group                                                                        base                                   changed
-----                                                                        ----                                   -------
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=1     1.55     39.1±1.25ms        ? ?/sec    1.00     25.2±0.35ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=16    1.72    83.7±11.82ms        ? ?/sec    1.00     48.6±2.81ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=1      1.03      2.9±0.02ms        ? ?/sec    1.00      2.8±0.01ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=16     1.02      5.8±2.13ms        ? ?/sec    1.00      5.6±2.12ms        ? ?/sec

Per-runner information
ipc_writer — shard 1/1

Node: gk3-benchmark-cluster-nap-gqsla0c0-ff8771d2-s6l4

Instance: c4a-highmem-16 (8 vCPU / 65 GiB)

uname:

Linux bench-c6665165258-4525-vcv9m 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench ipc_writer
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 55.0s
Peak memory 102.7 MiB
Avg memory 31.5 MiB
CPU user 166.2s
CPU sys 49.1s
Peak spill 0 B

branch

Metric Value
Wall time 50.0s
Peak memory 80.4 MiB
Avg memory 32.3 MiB
CPU user 195.0s
CPU sys 3.4s
Peak spill 0 B

File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: ipc_writer

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4
resources:
  cpu: '4'
shards: 1
Details
group                                                                        base                                   changed
-----                                                                        ----                                   -------
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=1     1.49     35.7±0.88ms        ? ?/sec    1.00     24.0±0.09ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=16    1.66   156.7±34.81ms        ? ?/sec    1.00     94.6±8.94ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=1      1.03      2.9±0.02ms        ? ?/sec    1.00      2.8±0.02ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=16     1.03     11.7±6.58ms        ? ?/sec    1.00     11.4±6.57ms        ? ?/sec

Per-runner information
ipc_writer — shard 1/1

Node: gk3-benchmark-cluster-nap-hr9recpb-6c82a1a3-s6dz

Instance: c4a-highmem-16 (4 vCPU / 65 GiB)

uname:

Linux bench-c6665162500-4524-684b2 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench ipc_writer
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 60.0s
Peak memory 111.1 MiB
Avg memory 37.2 MiB
CPU user 113.4s
CPU sys 32.9s
Peak spill 0 B

branch

Metric Value
Wall time 50.1s
Peak memory 81.4 MiB
Avg memory 37.1 MiB
CPU user 120.5s
CPU sys 1.5s
Peak spill 0 B

File an issue against this benchmark runner

@Rich-T-kid

Copy link
Copy Markdown
Contributor

run benchmark ipc_writer
env:
BENCH_FILTER: StreamEncoder/encode_10/lz4/ro
resources:
cpu: "2"

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: ipc_writer

Sharding factor: 1 (1 workers).

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4/ro
resources:
  cpu: '2'
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@Rich-T-kid

Copy link
Copy Markdown
Contributor

run benchmark ipc_writer
env:
BENCH_FILTER: StreamEncoder/encode_10/lz4/ro
resources:
cpu: "1"

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: ipc_writer

Sharding factor: 1 (1 workers).

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4/ro
resources:
  cpu: '1'
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@Rich-T-kid

Copy link
Copy Markdown
Contributor

just a bit curious 🤔

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: ipc_writer

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4/ro
resources:
  cpu: '2'
shards: 1
Details
group                                                                        base                                   changed
-----                                                                        ----                                   -------
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=1     1.46     35.3±0.66ms        ? ?/sec    1.00     24.2±0.09ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=16    1.68   329.2±39.11ms        ? ?/sec    1.00    196.3±1.51ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=1      1.02      2.9±0.02ms        ? ?/sec    1.00      2.8±0.02ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=16     1.02    23.3±12.11ms        ? ?/sec    1.00    22.9±12.15ms        ? ?/sec

Per-runner information
ipc_writer — shard 1/1

Node: gk3-benchmark-cluster-nap-1sbiwga9-ed3aa907-2bkt

Instance: c4a-highmem-16 (2 vCPU / 65 GiB)

uname:

Linux bench-c6666115948-4526-r8wgv 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench ipc_writer
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 80.2s
Peak memory 91.3 MiB
Avg memory 36.7 MiB
CPU user 88.2s
CPU sys 31.7s
Peak spill 0 B

branch

Metric Value
Wall time 65.0s
Peak memory 78.2 MiB
Avg memory 39.3 MiB
CPU user 92.4s
CPU sys 1.4s
Peak spill 0 B

File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: ipc_writer

Comparing ipc-lz4-reuse-frame-buffers (cb0c640) to 3ac3836 (merge-base) diff

Run configuration
run benchmark ipc_writer
env:
  BENCH_FILTER: StreamEncoder/encode_10/lz4/ro
resources:
  cpu: '1'
shards: 1
Details
group                                                                        base                                   changed
-----                                                                        ----                                   -------
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=1     1.49     36.2±0.70ms        ? ?/sec    1.00     24.3±0.17ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=65536/threads=16    1.69   665.3±38.98ms        ? ?/sec    1.00   394.4±18.29ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=1      1.03      2.9±0.04ms        ? ?/sec    1.00      2.8±0.04ms        ? ?/sec
arrow_ipc_stream_writer/StreamEncoder/encode_10/lz4/rows=8192/threads=16     1.03     48.4±8.57ms        ? ?/sec    1.00     46.8±9.18ms        ? ?/sec

Per-runner information
ipc_writer — shard 1/1

Node: gk3-benchmark-cluster-nap-1emaqzpa-d9be8adf-mmmj

Instance: c4a-highmem-16 (1 vCPU / 65 GiB)

uname:

Linux bench-c6666121446-4527-2kz9d 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench ipc_writer
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 110.4s
Peak memory 97.5 MiB
Avg memory 51.7 MiB
CPU user 73.3s
CPU sys 30.7s
Peak spill 0 B

branch

Metric Value
Wall time 85.3s
Peak memory 78.1 MiB
Avg memory 48.3 MiB
CPU user 76.8s
CPU sys 1.1s
Peak spill 0 B

File an issue against this benchmark runner

@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.

benchmark results look very strong!

this PR looks good, left a few suggestions

Comment thread arrow-ipc/src/compression.rs Resolved
Comment thread arrow-ipc/src/compression.rs Resolved
Comment thread arrow-ipc/src/compression.rs Outdated

#[test]
#[cfg(feature = "lz4")]
fn test_lz4_compression_reuses_context() {

@Rich-T-kid Rich-T-kid Nov 5, 2026 •

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.

This verifies correctness across repeated frames, but it would also pass if every call created a fresh encoder. Is there a stable way to assert that the same cached compressor is retained across calls? maybe we could assert the capacity?

we could also keep this test and rename it to test_lz4_compression_multiple_frames and create a separate test to assert the allocation

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.

🤔 FrameEncoder does not expose an API to inspect its internal buffer, so I don't think we can assert over the capacity. I could start comparing pointer addresses of the FrameEncoder, but I fear that'd make a brittle test in case someone changes something in the future.

What comes to mind is:

  • Rename the test as you suggested, and rely on it for ensuring correctness rather than reuse
  • Rely on the benchmark added in the previous PR for ensuring reuse (no reuse would show worst performance)

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.

yea I just took a look at their docs and I cant find anything we could use to assert this. any alternative does seem quite hacky. I think relying on the benchmarks should be fine.

@Rich-T-kid

Copy link
Copy Markdown
Contributor

thanks @gabotechs

@Rich-T-kid
Rich-T-kid added this pull request to the merge queue Nov 6, 2026
Merged via the queue into apache:main with commit 739f9cc Nov 6, 2026
23 checks passed
@Jefffrey Jefffrey added the performance Speed or memory optimizations label Nov 7, 2026
mohitgurav20 added a commit to mohitgurav20/arrow-rs that referenced this pull request Nov 14, 2026
Allow callers to choose 64 KiB / 256 KiB / 1 MiB / 4 MiB lz4 blocks via IpcWriteOptions, keeping 256 KiB as the default pinned by apache#12084. 8 MiB is excluded because the frame header's 3-bit block size code cannot represent it without setting the reserved bit, which the decoder rejects.

Generated-by: MiMo via OpenCode
mohitgurav20 added a commit to mohitgurav20/arrow-rs that referenced this pull request Nov 18, 2026
Allow callers to choose 64 KiB / 256 KiB / 1 MiB / 4 MiB lz4 blocks via IpcWriteOptions, keeping 256 KiB as the default pinned by apache#12084. 8 MiB is excluded because the frame header's 3-bit block size code cannot represent it without setting the reserved bit, which the decoder rejects.

Generated-by: MiMo via OpenCode
devdudumuniz pushed a commit to devdudumuniz/arrow-rs that referenced this pull request Nov 20, 2026
# Which issue does this PR close?

- Closes apache#12105

# Rationale for this change

apache#12084 pinned the reusable LZ4 frame encoder to a 256 KiB block size so
a reused encoder’s block size is not decided by the first buffer it
writes. Callers who want to trade retained encoder buffers against
compression ratio currently have no way to choose a different size. This
change lets callers configure the block size while keeping 256 KiB as
the default, so existing output remains unchanged.

# What changes are included in this PR?

- Adds `IpcWriteOptions::try_with_lz4_block_size(Option<usize>)`,
following the existing `try_with_compression_level` pattern with a
private field and validating builder.
- Supports 64 KiB, 256 KiB, 1 MiB, and 4 MiB, which are the block sizes
the LZ4 frame header can represent. The option requires metadata V5 or
newer and returns an error when used with ZSTD.
- Updates `IpcWriteContext` to store the selected size and discard its
cached encoder when that size changes. The setting is synced through the
shared record batch and dictionary batch encoding path.
- Preserves the selected size when `Lz4Compressor` rebuilds after a
mid-frame error.
- Does not support 8 MiB: `lz4_flex` sets a reserved frame-header bit
for that size, which its decoder rejects.

# Are these changes tested?

Tests cover the supported frame-header size codes and roundtrips,
byte-identical output for the default 256 KiB setting, and switching
block sizes while reusing an `IpcWriteContext`. They also cover
unsupported sizes, metadata V4, ZSTD in both builder-call orders, and
end-to-end roundtrips with nulls and a dictionary column.

# Are there any significant user-facing changes?

Yes. This adds the public `IpcWriteOptions::try_with_lz4_block_size`
method so callers can select an LZ4 frame block size. The addition is
non-breaking; when the option is unset, the 256 KiB default and encoded
output are unchanged.

# AI usage disclosure

Codex Desktop and OpenCode assisted with implementation, test updates,
and reviewer-driven revisions. I guided the changes based on the issue
and reviewer feedback. The branch was checked with local tests,
formatting, and lint.
ariel-miculas added a commit to ariel-miculas/arrow-rs that referenced this pull request Nov 23, 2026
…ing decoder

`decompress_lz4` opens an `lz4_flex::frame::FrameDecoder` per buffer, and none
of that decoder's streaming machinery is needed for the frames IPC carries.

`FrameDecoder` sizes its source and destination buffers from the maximum block
size the frame's header *declares*, and zero-fills the destination up to that
maximum before each block, whatever the block holds. The declared maximum has
nothing to do with how much data is behind it: a writer may declare 4 MiB blocks
for a buffer of any size, and Arrow C++ and Comet do. So decoding a few KiB can
cost megabytes of memset, and an IPC message decodes one buffer after another --
one per field node plus its validity and offsets, each its own frame.

Pooling one decoder in `DecompressionContext`, as the zstd arm already does for
its decompressor, would remove the repeated construction but not the zero-fill,
which happens once per block rather than once per decoder. A decoder cannot in
fact be carried between frames at all: `FrameDecoder` asserts its destination
capacity equals the declared maximum exactly, which a decoder that has seen a
linked frame no longer satisfies, and that assertion fires in debug builds as
soon as frames of differing block modes go through one decoder.

The blocks can instead be decompressed one after another straight into the
output with `lz4_flex::block::decompress_into`: no scratch buffer, nothing
zeroed beyond the output, and no dependence on what the header declares. A frame
outside that shape -- linked blocks, a block or content checksum, a dictionary,
a block size the format does not define -- still goes to the streaming decoder,
with a decoder of its own as before. Independent blocks and no checksums is what
every Arrow writer produces.

Like the streaming path, this never sizes the output from the advertised length
alone. That length comes from the IPC prefix and is untrusted, so the output
starts at no more than `MAX_PREALLOC_BYTES` and grows only as the blocks fill
it, bounded per block by the frame's declared maximum and by what the advertised
length leaves. A frame holding more than it advertised is reported as such
rather than decoded.

Measured through `arrow-ipc/benches/ipc_reader.rs`, reading 10 batches end to
end, so decompression is only part of each figure:

    no_validation/read_10/lz4                     2.14 ms ->  1.95 ms   -8.4%
    wide_200x4096/lz4_64kib_blocks                7.44 ms ->  4.15 ms  -44.3%
    wide_200x4096/lz4_4096kib_blocks             68.81 ms ->  4.16 ms  -93.9%
    wide_20x131072/lz4_64kib_blocks              15.30 ms -> 11.53 ms  -24.1%
    wide_20x131072/lz4_4096kib_blocks            21.38 ms -> 11.55 ms  -45.4%

Both zstd rows are unchanged (p = 0.15 and 0.13), and the two block sizes now
converge: what the header declares no longer decides what the read costs.

Allocations counted with the system allocator wrapped in a `GlobalAlloc` that
tallies every one, over the same reads -- a census, not a sample. Bytes and peak
in MiB; the zstd rows do not move and are left out:

    shape      blocks     allocations     bytes allocated       peak live
    4x8192     64 KiB    526 ->   366   12.47 ->     2.47    0.37 -> 0.25
               4 MiB     526 ->   366  642.47 ->     2.47    8.25 -> 0.25
    200x4096   64 KiB  24449 -> 16449  562.94 ->    62.94    6.42 -> 6.30
               4 MiB   24449 -> 16449  32062.94 ->  62.94   14.30 -> 6.30
    20x131072  64 KiB   2483 ->  1683  246.84 ->   196.84  19.81 -> 19.68
               4 MiB    2483 ->  1683  3396.82 ->   196.82  27.68 -> 19.68

Every delta accounts for itself exactly. The counts fall by 160, 8000 and 800
against 80, 4000 and 400 compressed buffers: two allocations per buffer, the
decoder's `src` and `dst`, and what remains matches the zstd arm, which already
pools its decompressor. The bytes fall by twice the declared block size per
buffer -- 80, 4000 and 400 buffers times 128 KiB, then times 8 MiB -- to the
byte in all six rows. On 200 columns at 4 MiB blocks that is 31.3 GiB allocated
to read a 30 MiB stream, and the figures no longer vary with the declared size
at all.

Measured as well through a Comet in-memory cache read, where each column's
buffers are compressed one at a time and the frames declare 4 MiB blocks. 5M
rows by 6 columns, full projection: 1105 ms to 259 ms. On a 300-column relation,
where a cached batch holds hundreds of buffers, 7519 ms to about the time the
same workload takes when the writer declares 64 KiB blocks instead.

New tests cover both paths against every frame shape: independent and linked
blocks, with and without a content checksum, over compressible and
incompressible payloads, plus truncated frames.

This is apache#11129, which was closed by apache#12084 -- that
PR pooled the frame *encoder* in `IpcWriteContext` and left the decoder as it
was.

Co-Authored-By: Claude Opus 5 <[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 performance Speed or memory optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants