GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Adaptive's buffers setBytes performance is held back by NIO Buffers allocations · Issue #15723 · netty/netty

Adaptive's buffers setBytes performance is held back by NIO Buffers allocations #15723

New issue
Copy link
New issue
Copy link
Closed
Task
#15728
#15727
Closed
Adaptive's buffers setBytes performance is held back by NIO Buffers allocations#15723
Task
#15728
#15727
Copy link
Labels
improvement
Milestone
4.2.11.Final

Description

@franz1981
franz1981
opened on Sep 29, 2025
Issue body actions

This is still another performance issue for users which cannot use Unsafe buffers.

Image

This is a flamegraph collected while running Techempower plaintext while Nettyread data out of Network using NIO and point to

netty/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java

Line 350 in a4a2e05

return byteBuf.writeBytes(javaChannel(), allocHandle.attemptedBytesRead());

But something similar can still happen on epoll (our native impl) too

netty/transport-classes-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollChannel.java

Line 368 in a4a2e05

ByteBuffer buf = byteBuf.internalNioBuffer(writerIndex, byteBuf.writableBytes());
if ByteBuf::hasMemoryAddress return false.

I would focus on the NIO case here which is calling

netty/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java

Lines 1831 to 1838 in a4a2e05

public int setBytes(int index, FileChannel in, long position, int length)
throws IOException {
try {
return in.read(internalNioBuffer(index, length).duplicate(), position);
} catch (ClosedChannelException ignored) {
return -1;
}
}

and

netty/buffer/src/main/java/io/netty/buffer/UnpooledDirectByteBuf.java

Lines 768 to 771 in f03179b

public ByteBuffer nioBuffer(int index, int length) {
checkIndex(index, length);
return ((ByteBuffer) buffer.duplicate().position(index).limit(index + length)).slice();
}

Which means that:

  • adaptive allocates from the rootParent::nioBuffer a buffer duplicate and a slice of it
  • adaptive further create another duplicate of this

I believe we could reduce the number of allocations there for the no Unsafe version.

Activity

Next
  1. franz1981 commented on Sep 29, 2025

    @franz1981
    franz1981
    on Sep 29, 2025
    ContributorAuthor
    More actions

    FYI @yawkat ^^

  2. franz1981
    added the
    Task
    issue type on Sep 29, 2025
  3. franz1981
    added
    improvement
    on Sep 29, 2025
  4. franz1981 commented on Sep 29, 2025

    @franz1981
    franz1981
    on Sep 29, 2025
    ContributorAuthor
    More actions

    @chrisvest this is kind of related to #15402

  5. franz1981 commented on Sep 29, 2025

    @franz1981
    franz1981
    on Sep 29, 2025
    ContributorAuthor
    More actions

    I see that what we can do there is:

    • if tmpBuf is created just duplicate it
    • if tmpBuf is NOT created, create a duplicate of the original buffer instead, no need to slice it but just limiting it in the right way

    This can be used for each method which need a duplicate really, since it will create it regardless.
    If lucky, at least on reader side, tmpBuf won't be created at all and we will save one copy.

  6. chrisvest commented on Sep 29, 2025

    @chrisvest
    chrisvest
    on Sep 29, 2025
    Member
    More actions

    Alternatively we can use slice(int index, int length) on Java 13 onwards

    Reacted by Francesco Nigro
  7. franz1981 commented on Sep 29, 2025

    @franz1981
    franz1981
    on Sep 29, 2025
    ContributorAuthor
    More actions

    Alternatively we can use slice(int index, int length) on Java 13 onwards

    Since we expect people to move at runtime past 17 (fingers crossed, is what I suggest to our customers :) ). I'm all in for this @chrisvest

    Do you have cycles to send a PR on this?

  8. chrisvest commented on Sep 29, 2025

    @chrisvest
    chrisvest
    on Sep 29, 2025
    Member
    More actions

    Yeah, I can have a PR up in a few.

    Reacted by Francesco Nigro
  9. chrisvest
    added 2 commits that reference this issue on Sep 29, 2025

    Faster slicing of unpooled direct buffers

    07972df

    Avoid buffer duplication in AdaptiveByteBuf.setBytes

    319d98f
  10. normanmaurer
    closed this as completedin #15728on Sep 30, 2025
  11. normanmaurer
    added a commit that references this issue on Sep 30, 2025

    Avoid buffer duplication in AdaptiveByteBuf.setBytes (#15728)

    45160d6
  12. normanmaurer
    added this to the 4.2.7.Final milestone on Sep 30, 2025
  13. normanmaurer
    added a commit that references this issue on Sep 30, 2025

    Faster slicing of unpooled direct buffers (#15727)

    092ce05
  14. pull
    added a commit that references this issue on Sep 30, 2025

    Avoid buffer duplication in AdaptiveByteBuf.setBytes (netty#15728)

    06f8920
  15. 11 remaining items

  16. normanmaurer
    added this to the 4.2.8.Final milestone on Oct 13, 2025
  17. normanmaurer
    modified the milestones: 4.2.8.Final, 4.2.9.Final, 4.2.10.Final on Dec 15, 2025
  18. normanmaurer
    modified the milestones: 4.2.10.Final, 4.2.11.Final on Feb 5, 2026
  19. normanmaurer
    modified the milestones: 4.2.11.Final, 4.2.12.Final on Mar 25, 2026
  20. normanmaurer commented on Mar 25, 2026

    @normanmaurer
    normanmaurer
    on Mar 25, 2026
    Member
    More actions

    @franz1981 whereare we with this one ?

  21. franz1981 commented on Mar 25, 2026

    @franz1981
    franz1981
    on Mar 25, 2026
    ContributorAuthor
    More actions

    I think @chrisvest fixed it. Today I am on vacation but d9a8b00 should be the guilty commit which fixed it

  22. normanmaurer commented on Mar 25, 2026

    @normanmaurer
    normanmaurer
    on Mar 25, 2026
    Member
    More actions

    Ok let me close it now...

  23. normanmaurer
    closed this as completedon Mar 25, 2026
  24. chrisvest
    modified the milestones: 4.2.12.Final, 4.2.11.Final on Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    improvement

    Type

    Task

    Projects

    No projects

      Milestone

      • 4.2.11.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.