Skip to content

feat(arrow-ipc): make lz4 block size configurable - #12148

Merged
Rich-T-kid merged 3 commits into
apache:mainfrom
mohitgurav20:12105-lz4-block-size
Nov 19, 2026
Merged

Rich-T-kid merged 3 commits into
apache:mainfrom
mohitgurav20:12105-lz4-block-size

Conversation

@mohitgurav20

@mohitgurav20 mohitgurav20 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

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

@boring-cyborg boring-cyborg Bot added the arrow-ipc arrow-ipc crate label Nov 10, 2026
@Rich-T-kid
Rich-T-kid self-requested a review November 10, 2026 18:45

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

I think this change should be much smaller. It may be a good idea to split up the reader side from the writer side

Comment thread arrow-ipc/src/compression.rs Resolved
Comment thread arrow-ipc/src/compression.rs Resolved
@mohitgurav20

Copy link
Copy Markdown
Contributor Author

Yeah sir will work on 85 nd make the changess

@Rich-T-kid

Copy link
Copy Markdown
Contributor

is this ready for another review?

@mohitgurav20

mohitgurav20 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

@Rich-T-kid
yeah its ready but the some workflows are pending sirr.

@Rich-T-kid
Rich-T-kid self-requested a review November 12, 2026 16:22
@mohitgurav20

Copy link
Copy Markdown
Contributor Author

@Rich-T-kid sir now you can have a look and feel free to admit any changes to done by my side the ci checks greens

@Rich-T-kid

Copy link
Copy Markdown
Contributor

will take another look this afternoon

@mohitgurav20

Copy link
Copy Markdown
Contributor Author

@Rich-T-kid for sure no worries ill be happy to address if u suggest any changes and take ur time to look on this issue

Comment thread arrow-ipc/src/compression.rs Resolved
Comment thread arrow-ipc/src/compression.rs Resolved
Comment thread arrow-ipc/src/compression.rs Resolved
Comment thread arrow-ipc/src/compression.rs Resolved
Comment thread arrow-ipc/src/compression.rs Resolved
Comment thread arrow-ipc/src/writer.rs Resolved
Comment thread arrow-ipc/src/writer.rs Resolved
@mohitgurav20

Copy link
Copy Markdown
Contributor Author

Thanks for the review @Rich-T-kid . I linked the LZ4 frame specification . removed the redundant comments, and updated the encoder comment to explain why the selected block size is pinned. I also changed the test to reuse one IpcWriteContext while switching block sizes, and kept the round-trip checks. I haven’t been able to run the test locally yet because my MSVC toolchain is missing link.exe.

@Rich-T-kid

Copy link
Copy Markdown
Contributor

@mohitgurav20 can you resolve the threads that you have addressed. it just makes it easier for me. 🙇

@mohitgurav20

Copy link
Copy Markdown
Contributor Author

Yeah wait for a while sir get back to it easier to understand

@Rich-T-kid
Rich-T-kid self-requested a review November 14, 2026 02:47
@mohitgurav20

Copy link
Copy Markdown
Contributor Author

@Rich-T-kid done sir i have addressed the changes just waiting for ci checks to turn green . u can have a look on it

@Rich-T-kid Rich-T-kid added the enhancement New feature/addition label Nov 16, 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
Represent supported block sizes with an internal enum, reduce redundant tests, and reject ZSTD regardless of builder call order.

Generated-by: Codex (GPT-6)
Link the frame specification, remove redundant comments, and reuse one IPC write context across block sizes in the end-to-end test.

Generated-by: Codex Desktop v26.1105.1297

@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 for the iteration @mohitgurav20, this should be good to go after addressing the two comments

Comment thread arrow-ipc/src/writer.rs
Comment on lines +455 to +457
/// [`ArrowError::InvalidArgumentError`]. Like the other compression settings this requires
/// metadata version V5 or newer, and it has no effect when another compression codec is
/// selected.

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.

combining this with ZSTD returns an error

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.

Yeahh sirr will work on this thanks for the help

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.

Yes, that combination returns an error. The builder checks the selected codec regardless of call order, and the tests cover setting ZSTD before and after the LZ4 block size.

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.

@mohitgurav20 could you point that out in the doc comment

Comment thread arrow-ipc/src/writer.rs
@@ -27,7 +27,7 @@ use arrow_data::{ArrayData, ArrayDataBuilder, BufferSpec, layout};
use arrow_schema::*;

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.

nit: this does have a public facing change as there a new method, could you update the pr description

@mohitgurav20

Copy link
Copy Markdown
Contributor Author

Thanks for the review @Rich-T-kid sirr I’ve updated the PR description to mention the new public method, and confirmed that combining the LZ4 block-size option with ZSTD returns an error in either builder-call order. Please let me know if you’d like any further changes, I’m happy to address them

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

thank you for the iteration @mohitgurav20

@mohitgurav20

Copy link
Copy Markdown
Contributor Author

@Rich-T-kid sir i hv updated the docs to clarify that an LZ4 block size can’t be combined with ZSTD, regardless of which option is set first. I also noted that the block size can be cleared with None before selecting ZSTD. Thanks for catching that.

@mohitgurav20

Copy link
Copy Markdown
Contributor Author

have a nice day sir

@Rich-T-kid
Rich-T-kid added this pull request to the merge queue Nov 19, 2026
Merged via the queue into apache:main with commit 3e7ca97 Nov 19, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-ipc arrow-ipc crate enhancement New feature/addition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the Arrow IPC LZ4 block size configurable

2 participants