Skip to content

[#2646] feat(netty): Support converting CompositeByteBuf to a direct nio buffer#2732

Draft
wForget wants to merge 1 commit intoapache:masterfrom
wForget:UNIFFLE-2646
Draft

[#2646] feat(netty): Support converting CompositeByteBuf to a direct nio buffer#2732
wForget wants to merge 1 commit intoapache:masterfrom
wForget:UNIFFLE-2646

Conversation

@wForget
Copy link
Copy Markdown
Member

@wForget wForget commented Feb 25, 2026

What changes were proposed in this pull request?

Support converting CompositeByteBuf to a direct nio buffer

Why are the changes needed?

CompositeByteBuf.nioBuffer will return a heap buffer if the composite buffer has more than one component, even if all components are direct buffers. In native client scenarios (like gluten), we prefer to use direct buffer to reduce data copying.

closes #2646

Does this PR introduce any user-facing change?

yes, a new configuration

How was this patch tested?

Tested it locally, after adding the following configuration, the gluten shuffle reader will use LowCopyNettyJniByteInputStream.

spark.executorEnv.RSS_NETTY_PREFER_DIRECT_FOR_COMPOSITE_BUFFER=true

if (buf instanceof CompositeByteBuf && buf.isDirect() && buf.nioBufferCount() > 1
&& NettyUtils.preferDirectForCompositeBuffer()) {
int length = buf.readableBytes();
ByteBuffer merged = ByteBuffer.allocateDirect(length).order(buf.order());
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Although this still involves one data copy, it is an improvement for gluten scenarios.

  • Before, there were two data copies: Netty direct buffer → NIO heap buffer → Gluten native side.
  • After, there is only one data copy: Netty direct buffer → NIO direct buffer → Gluten native side (no copy).

@wForget
Copy link
Copy Markdown
Member Author

wForget commented Feb 25, 2026

cc @zuston

@github-actions
Copy link
Copy Markdown

Test Results

 3 185 files  ±0   3 185 suites  ±0   6h 51m 16s ⏱️ -11s
 1 245 tests ±0   1 244 ✅ ±0   1 💤 ±0  0 ❌ ±0 
15 774 runs  ±0  15 759 ✅ ±0  15 💤 ±0  0 ❌ ±0 

Results for commit c8e30e3. ± Comparison against base commit 9c0c27d.

Copy link
Copy Markdown
Member

@zuston zuston left a comment

Choose a reason for hiding this comment

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

It looks OK for me, but I hope the related options could be scoped into the RssClientConf.java

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.

[FEATURE] zero-copy for reading when integrating gluten

2 participants