Skip to content

DecodeBuffer API - #16076

Draft
yawkat wants to merge 1 commit into
4.2from
decode-buffer
Draft

yawkat wants to merge 1 commit into
4.2from
decode-buffer

Conversation

@yawkat

@yawkat yawkat commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

Motivation:

Many netty codecs accumulate input data in a buffer and decode it iteratively. ByteToMessageDecoder is the most prominent example. The implementations are scattered and come with tradeoffs:

  • When using CompositeByteBuf, indexed buffer access is more expensive.
  • When using a single large cumulation buffer, there are copy operations.
  • Discarding read bytes is impossible if the decoder uses readRetainedSlice and keeps a reference to some read bytes.

Modification:

Introduce a new DecodeBuffer class that implements a composite-like cumulation approach, but uses temporary buffers for decode operations.

Result:

Avoid CompositeByteBuf for the single-buffer base case.

Any readRetainedSlice calls avoid locking the entire buffered input forever, though they still prevent the full CompositeByteBuf for that decode operation from being released.

Motivation:

Many netty codecs accumulate input data in a buffer and decode it iteratively. ByteToMessageDecoder is the most prominent example. The implementations are scattered and come with tradeoffs:

- When using CompositeByteBuf, indexed buffer access is more expensive.
- When using a single large cumulation buffer, there are copy operations.
- Discarding read bytes is impossible if the decoder uses readRetainedSlice and keeps a reference to some read bytes.

Modification:

Introduce a new DecodeBuffer class that implements a composite-like cumulation approach, but uses temporary buffers for decode operations.

Result:

Avoid CompositeByteBuf for the single-buffer base case.

Any readRetainedSlice calls avoid locking the *entire* buffered input forever, though they still prevent the full CompositeByteBuf for that decode operation from being released.
@yawkat

yawkat commented Dec 19, 2025

Copy link
Copy Markdown
Contributor Author

Possible applications are:

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.

1 participant