Skip to content

Precompute segments offsets and use them as segment's identity#15509

Merged
chrisvest merged 2 commits into
netty:4.2from
franz1981:4.2_nosegmentid
Aug 5, 2025
Merged

Precompute segments offsets and use them as segment's identity#15509
chrisvest merged 2 commits into
netty:4.2from
franz1981:4.2_nosegmentid

Conversation

@franz1981

Copy link
Copy Markdown
Contributor

Motivation:

Reusing a segment perform a data-dependent multiply to obtain the recycled segment's starting index slowing down segment's allocation

Modifications:

Store in the segments free-list the precomputed offsets, performing just a lookup

Result:

Faster segment's allocation

Motivation:

Reusing a segment perform a data-dependent multiply to obtain the recycled segment's starting index slowing down segment's allocation

Modifications:

Store in the segments free-list the precomputed offsets, performing just a lookup

Result:

Faster segment's allocation
@franz1981

franz1981 commented Jul 19, 2025

Copy link
Copy Markdown
Contributor Author

This is not key but the freelist::fill could be improved by adding a constructor where we can allocate the list's array with a simple Arrays::copyOf(segmentOffsets, nextPow2Size)

Whilst a more contained change could be by just changing free list fill to perform the multiplication on the fly using the counter.

@franz1981 franz1981 requested a review from Copilot July 19, 2025 08:04

Copilot AI left a comment

Copy link
Copy Markdown

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 optimizes segment allocation in the adaptive pooling allocator by precomputing segment offsets and storing them directly in the free list, eliminating the need for runtime multiplication to calculate segment starting positions.

  • Precomputes segment offsets at chunk controller factory initialization
  • Stores actual offset values in the free list instead of segment IDs
  • Removes segment ID tracking by using start index as both adjustment and segment identifier

Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java
Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java
@chrisvest chrisvest merged commit 2b73259 into netty:4.2 Aug 5, 2025
18 checks passed
@chrisvest

Copy link
Copy Markdown
Member

Thanks!

normanmaurer pushed a commit that referenced this pull request Sep 15, 2025
Motivation:

Reusing a segment perform a data-dependent multiply to obtain the
recycled segment's starting index slowing down segment's allocation

Modifications:

Store in the segments free-list the precomputed offsets, performing just
a lookup

Result:

Faster segment's allocation

Co-authored-by: Chris Vest <christianvest_hansen@apple.com>
normanmaurer added a commit that referenced this pull request Sep 15, 2025
… (#15656)

Motivation:

Reusing a segment perform a data-dependent multiply to obtain the
recycled segment's starting index slowing down segment's allocation

Modifications:

Store in the segments free-list the precomputed offsets, performing just
a lookup

Result:

Faster segment's allocation

Co-authored-by: Francesco Nigro <nigro.fra@gmail.com>
Co-authored-by: Chris Vest <christianvest_hansen@apple.com>
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.

3 participants