Skip to content

Eliminate ByteBuf copy in chunk translator#6311

Merged
onebeastchris merged 1 commit into
GeyserMC:masterfrom
iwmedia:feature/eliminate-bytebuf-copy-chunk-translator
Apr 21, 2026
Merged

Eliminate ByteBuf copy in chunk translator#6311
onebeastchris merged 1 commit into
GeyserMC:masterfrom
iwmedia:feature/eliminate-bytebuf-copy-chunk-translator

Conversation

@ByteExceptionM

@ByteExceptionM ByteExceptionM commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

The chunk translator was copying the ByteBuf into a byte array and then wrapping it again into a new buffer for the packet. That means every chunk that gets sent briefly exists twice in memory. Removed that extra copy by passing the buffer directly to the packet via retainedSlice(). This cuts memory usage per chunk in half during translation and reduces GC pressure, especially noticeable when players are loading lots of chunks at once.

Copilot AI review requested due to automatic review settings April 19, 2026 18:53

Copilot AI 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.

Pull request overview

This PR aims to reduce chunk translation overhead by removing an intermediate byte[] copy when building the Bedrock LevelChunkPacket, instead passing a Netty ByteBuf slice directly.

Changes:

  • Removes copying ByteBuf contents into a byte[] and wrapping it again for the packet payload.
  • Sends LevelChunkPacket with byteBuf.retainedSlice() as the data payload.
  • Switches the output buffer allocation from ByteBufAllocator.DEFAULT.ioBuffer(size) to Unpooled.buffer(size).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@valaphee valaphee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@onebeastchris onebeastchris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@onebeastchris onebeastchris merged commit 7a91743 into GeyserMC:master Apr 21, 2026
5 of 6 checks passed
@ByteExceptionM ByteExceptionM deleted the feature/eliminate-bytebuf-copy-chunk-translator branch April 21, 2026 16:54
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.

4 participants