Skip to content

[core][python] Increase default BLOB copy buffer to 256 KiB - #11535

Merged
JingsongLi merged 4 commits into
apache:masterfrom
JingsongLi:codex/blob-copy-buffer-256k
Nov 30, 2026
Merged

JingsongLi merged 4 commits into
apache:masterfrom
JingsongLi:codex/blob-copy-buffer-256k

Conversation

@JingsongLi

@JingsongLi JingsongLi commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Increase the default blob.copy-buffer-size from 4 KiB to 256 KiB in Java and PyPaimon. PyPaimon forwards the default through its resolved write options so the released native runtime picks it up.

In a single-writer Java 8 benchmark with 8 MiB BLOBs and local output, median throughput rose from 938 to 3,405 MiB/s with local input and from 249 to 317 MiB/s with loopback HTTP input.

Java now allocates its copy buffer on the first streamed payload that needs it. For known-length BlobRef values, the first allocation is bounded by the payload length and configured cap. Growth doubles the capacity up to that cap, covers the requested size, and releases the previous scratch array before allocating its replacement. In an allocation probe with 1,024 references of increasing length, cumulative writer-thread allocation dropped from 124.85 MiB with exact growth to 0.70 MiB. Inline BlobData uses the original array for chunked CRC updates and writes. A construction-only probe with 128 Java writers measured 32 MiB of copy buffers with eager 256 KiB allocation and 0 bytes with lazy allocation.

PyPaimon tracks the remaining length while copying bounded BLOB and video references. The copy loop adjusts requests after short reads and queries the starting position once.

The companion Rust change is apache/paimon-rust#1563.

Tests

  • 126 Java tests passed across BLOB and video formats, transfer metrics, Data Evolution updates, primary-key BLOB writes, and default option validation. The 104 BLOB and video tests were rerun after the scratch-buffer growth fix.
  • A Java 8 G1 probe with a 96 MiB heap and a 64 MiB copy-buffer setting wrote both a 40 MiB and a 41 MiB reference after the growth fix. The earlier implementation encountered an out-of-memory error on the second reference.
  • 193 Python BLOB and video tests passed, with one skipped. All 122 native BLOB tests passed with pypaimon-rust==0.5.0, including the 256 KiB default and a 3-byte explicit override.
  • Python flake8 passed on changed files.

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

Reviewed base master at head 08c2f64. Full file list (13 files): generated config docs, paimon-api/CoreOptions.java, paimon-format blob writers (AbstractBlobElementWriter, BlobFormatWriter), PyPaimon (core_options.py, native_commit.py, blob_format_writer.py, video_format_writer.py, table/row/blob.py), and four test files.

Core change notice: this changes the default of the public table option blob.copy-buffer-size (4 KiB to 256 KiB) across Java, PyPaimon, and the native runtime forwarding, plus the generic BLOB copy path in paimon-format shared by append BLOB writes, primary-key BLOB writes, and video packing. All engines writing BLOB payloads are affected; explicit settings still win.

Analysis:

  • Java lazy buffer: allocation happens on first need, bounded by min(payload length, cap) for known-length refs; growth doubles up to the cap and covers the request, so small blobs never pay 256 KiB and construction-only writers allocate nothing (probe tests assert buffer identity/size across a sequence of lengths, including the unknown-length fallback reusing the grown buffer).
  • Inline BlobData fast path is exact-class only, so subclasses overriding newInputStream still go through the stream path (dedicated subclass test); chunked writes use the original array with correct offset/length for both CRC and output, verified by an offset-recording wrapper.
  • The reworked writeBlobData preserves the previous semantics: reused bounded streams are not closed and are discarded on failure; owned streams are closed via try-with-resources on all paths; metrics accounting reads/writes the same byte counts, with the inline path feeding chunks without reads. Zero-length refs short-circuit before allocation.
  • PyPaimon: OffsetInputStream._read_chunks tracks remaining length, adjusts requests after short reads, and queries tell once per copy (request-sequence test with a 2-byte short-read stream); the fast path is exact-type gated like Java. native_commit uses setdefault, so explicit user/table values are never overridden and older native runtimes receive the new default.
  • Default sync: CoreOptions, BlobFormatWriter.DEFAULT_COPY_BUFFER_SIZE, Python BUFFER_SIZE, and the generated docs all agree on 256 KiB; validation bounds are unchanged.

No findings. Test coverage is thorough on both sides (Java 126, Python 193 + 122 native per the description), including default/override chunk-size assertions against recording readers.

CI note: checks are still initializing on this head; the author ran the Java and Python suites locally with flake8 clean. Approving without waiting for CI. Companion Rust default change: apache/paimon-rust#1563.

LGTM.

@JingsongLi
JingsongLi merged commit b5217bb into apache:master Nov 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants