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 — Remove reference counting from size classed chunks by franz1981 · Pull Request #16306 · netty/netty

Conversation

@franz1981

@franz1981 franz1981 commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Motivation:

SizeClassedChunk performs 2 atomic ops (retain/release) per allocation cycle on the hot path.

Modification:

Replace ref counting with a segment-count state machine that only needs atomics on the cold deallocation path.

Result:

No more per-allocation atomic operations for SizeClassedChunk.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@franz1981

franz1981 commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

This is a change coming from #15741 @ 8953bbe

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented Feb 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

FYI @laosijikaichele this should deliver quite a decent boost 🗡️
in pretty much ALL cases, non thread locals and thread locals in particular ^^

@chrisvest sadly I have left the ref cnt to still be allocated per chunk, due to other optimizations, but it shouldn't be used

laosijikaichele and chrisvest reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
franz1981 requested review from chrisvest and normanmaurer February 19, 2026 09:30
@franz1981

franz1981 commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

This is ready to go @normanmaurer in term of perf numbers I have already performed tests a lot for other prs on this, and the numbers were showing 1.5X or 2.X better perf for the thread local allocations

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
franz1981 force-pushed the 4.2_rm_rf_cnt_chunks branch from 0eefff6 to 842abd9 Compare February 19, 2026 09:41
@normanmaurer normanmaurer added this to the 4.2.11.Final milestone Feb 19, 2026
@franz1981

franz1981 commented Feb 21, 2026

Copy link
Copy Markdown
Contributor Author

@laosijikaichele I will check if using your perf test on mimalloc, but sadly we don't have the same HW so I will likely get some different numbers 😢
But last time I tried this, it was speeding things up a lot

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@laosijikaichele

laosijikaichele commented Feb 21, 2026

Copy link
Copy Markdown
Contributor

@franz1981 great work, no worries about the hardware, we can mainly compare the number change on adaptive, before and after this PR, to see the improvement.

franz1981 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest chrisvest added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Feb 21, 2026
@normanmaurer

normanmaurer commented Feb 23, 2026

Copy link
Copy Markdown
Member

@chrisvest @laosijikaichele @yawkat PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer
normanmaurer requested changes Feb 23, 2026
View reviewed changes
Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
franz1981 force-pushed the 4.2_rm_rf_cnt_chunks branch from e5751d6 to 21f7420 Compare February 23, 2026 15:06
@franz1981

franz1981 commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

PTAL @normanmaurer I have simplified the capacity method to make it inlineable, but TBH it's the logic there which concern me, since mpsc::size is not "trivial" (is a loop!)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

@laosijikaichele I was wrong, it seems to improve, on my x86 by a mere ~7-8% atm, maybe you will have better luck with aarch64?
Now the most relevant cost is the single buffer release :"( (due to the new RefCnt indirection and VarHandle usage)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

When i see things like these my heart is bleeding 😢

   0.10%    0x00007f1ddc2103cb:   jg     0x00007f1ddc21118c           ;*if_icmpgt {reexecute=0 rethrow=0 return_oop=0}
                                                                      ; - io.netty.buffer.AdaptivePoolingAllocator::allocate@7 (line 260)
            0x00007f1ddc2103d1:   lea    0x1f(%rdx),%r8d
   4.09%    0x00007f1ddc2103d5:   sar    $0x5,%r8d                    ;*ishr {reexecute=0 rethrow=0 return_oop=0}
                                                                      ; - io.netty.buffer.AdaptivePoolingAllocator::sizeIndexOf@5 (line 282)
                                                                      ; - io.netty.buffer.AdaptivePoolingAllocator::sizeClassIndexOf@1 (line 286)
                                                                      ; - io.netty.buffer.AdaptivePoolingAllocator::allocate@11 (line 261)

I know that is a data dep but, c'mon...on Intel this the lea is faster...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
franz1981 force-pushed the 4.2_rm_rf_cnt_chunks branch 2 times, most recently from dfb6661 to 674ce6b Compare February 23, 2026 15:50
@franz1981

franz1981 commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

@laosijikaichele i would be curious how the numbers now look vs mimalloc to understand the gap left (assuming proper sized chunk q 😢)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chrisvest
chrisvest previously approved these changes Feb 23, 2026
View reviewed changes

@chrisvest chrisvest left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

One nit but overall this looks good.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
franz1981 force-pushed the 4.2_rm_rf_cnt_chunks branch from 674ce6b to 81de40e Compare February 23, 2026 20:10
@franz1981

franz1981 commented Feb 23, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Results on my machine
without thread local accesses

  ┌────────────────────────┬──────────────────────┬──────────────────────┬───────┐
  │        Scenario        │  Before (77e2a683)   │   After (6975d4e7)   │ Delta │
  ├────────────────────────┼──────────────────────┼──────────────────────┼───────┤
  │ Default                │ 63.368 ± 1.487 ns/op │ 60.635 ± 0.900 ns/op │ -4.3% │
  ├────────────────────────┼──────────────────────┼──────────────────────┼───────┤
  │ --enable-native-access │ 62.687 ± 0.828 ns/op │ 59.861 ± 0.240 ns/op │ -4.5% │
  └────────────────────────┴──────────────────────┴──────────────────────┴───────┘

and thread local one

  ┌───────────────────────────────────────────┬──────────────────────┬──────────────────────┬────────┐
  │                 Scenario                  │  Before (77e2a683)   │   After (6975d4e7)   │ Delta  │
  ├───────────────────────────────────────────┼──────────────────────┼──────────────────────┼────────┤
  │ Custom executor                           │ 37.993 ± 0.762 ns/op │ 35.543 ± 0.936 ns/op │ -6.4%  │
  ├───────────────────────────────────────────┼──────────────────────┼──────────────────────┼────────┤
  │ Custom executor + native-access           │ 39.102 ± 0.503 ns/op │ 34.715 ± 0.704 ns/op │ -11.2% │
  └───────────────────────────────────────────┴──────────────────────┴──────────────────────┴────────┘

Not wow, but not terrible.
Let's say the most of the improvements were already rolled out in the previous PR i made@ #15741
Would be nice to see how much aarch64 benefit from removing atomic ops in the hot path (twice atomic ops)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer
normanmaurer requested changes Feb 23, 2026
View reviewed changes
Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
franz1981 force-pushed the 4.2_rm_rf_cnt_chunks branch from d0afc55 to d921c93 Compare February 23, 2026 20:12
@franz1981

franz1981 commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

And the other hidden performance benefit is that we now have scalable allocate/release from different threads - because it will scale as much as the underlying mpsc queue, while before it was "limited" by the shared "chunk" ref cnt. It's a pathological case, but still, worth mentioning.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yawkat
yawkat reviewed Feb 23, 2026
View reviewed changes
Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

yawkat
yawkat reviewed Feb 23, 2026
View reviewed changes
Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

PTAL @normanmaurer if you're happy with the first numbers at #16306 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest
chrisvest dismissed their stale review February 23, 2026 22:47

Code was updated

franz1981 added 9 commits February 26, 2026 09:57
@franz1981
Remove reference counting from size classed chunks
0fc7738
Motivation:

SizeClassedChunk performs 2 atomic ops (retain/release) per allocation
cycle on the hot path.

Modification:

Replace ref counting with a segment-count state machine that only
needs atomics on the cold deallocation path.

Result:

No more per-allocation atomic operations for SizeClassedChunk.
@franz1981
Refactor remainingCapacity calculation and deallocation logic in Adap…
cf9083d
…tivePoolingAllocator
@franz1981
Refactor state handling in AdaptivePoolingAllocator to simplify deall…
4f63acf
…ocation logic
@franz1981
Address Chris's comments
02559c3
@franz1981
Address Norman's comments
c040028
@franz1981
Address Jonas comments
6947b45
@franz1981
Address Jonas comments (2)
8a5cfd3
@franz1981
Refactor chunk queue to use SizeClassedChunk for improved type safety…
4c81dcf
… and capacity checks
@franz1981
Fix logic in AdaptivePoolingAllocator
dec518f
@franz1981
franz1981 force-pushed the 4.2_rm_rf_cnt_chunks branch from 6c181fb to dec518f Compare February 26, 2026 08:58
@franz1981

franz1981 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

PTAL @normanmaurer

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

@chrisvest done bud ! Let's see if the CI is happy ;)
Right after this @laosijikaichele if you are interested we can take a look to fix the chunk reuse q, which is not good ATM (the offer/poll storm is not good at all), maybe with @chrisvest ? wdyt?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

CI is green @normanmaurer @chrisvest so, ready to go?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chrisvest
chrisvest approved these changes Feb 26, 2026
View reviewed changes
@chrisvest
chrisvest merged commit de25e7a into netty:4.2 Feb 26, 2026
19 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest

chrisvest commented Feb 26, 2026

Copy link
Copy Markdown
Member

Very nice. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot

netty-project-bot commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 4.1.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

netty-project-bot pushed a commit that referenced this pull request Feb 26, 2026
@franz1981 @netty-project-bot
Remove reference counting from size classed chunks (#16306)
a861106
Motivation:

SizeClassedChunk performs 2 atomic ops (retain/release) per allocation
cycle on the hot path.

Modification:

Replace ref counting with a segment-count state machine that only needs
atomics on the cold deallocation path.

Result:

No more per-allocation atomic operations for SizeClassedChunk.

(cherry picked from commit de25e7a)
@netty-project-bot

netty-project-bot commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #16378

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Feb 26, 2026
@netty-project-bot netty-project-bot mentioned this pull request Feb 26, 2026
Auto-port 5.0: Remove reference counting from size classed chunks #16378
Merged
chrisvest pushed a commit to chrisvest/netty that referenced this pull request Feb 26, 2026
@franz1981 @chrisvest
Remove reference counting from size classed chunks (netty#16306)
ed65b59
Motivation:

SizeClassedChunk performs 2 atomic ops (retain/release) per allocation
cycle on the hot path.

Modification:

Replace ref counting with a segment-count state machine that only needs
atomics on the cold deallocation path.

Result:

No more per-allocation atomic operations for SizeClassedChunk.

(cherry picked from commit de25e7a)
@chrisvest

chrisvest commented Feb 26, 2026

Copy link
Copy Markdown
Member

Port PR for 4.1: #16379

franz1981 reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest chrisvest removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Feb 26, 2026
chrisvest added a commit that referenced this pull request Feb 26, 2026
@chrisvest @franz1981
Remove reference counting from size classed chunks (#16306) (#16379)
ebb66f9
Motivation:

SizeClassedChunk performs 2 atomic ops (retain/release) per allocation
cycle on the hot path.

Modification:

Replace ref counting with a segment-count state machine that only needs
atomics on the cold deallocation path.

Result:

No more per-allocation atomic operations for SizeClassedChunk.

(cherry picked from commit de25e7a)

Co-authored-by: Francesco Nigro <[email protected]>
@franz1981
franz1981 deleted the 4.2_rm_rf_cnt_chunks branch February 27, 2026 12:55
chrisvest pushed a commit that referenced this pull request Feb 27, 2026
@netty-project-bot @franz1981
Auto-port 5.0: Remove reference counting from size classed chunks (#1…
900aaca
…6378)

Auto-port of #16306 to 5.0
Cherry-picked commit: de25e7a

---
Motivation:

SizeClassedChunk performs 2 atomic ops (retain/release) per allocation
cycle on the hot path.

Modification:

Replace ref counting with a segment-count state machine that only needs
atomics on the cold deallocation path.

Result:

No more per-allocation atomic operations for SizeClassedChunk.

Co-authored-by: Francesco Nigro <[email protected]>
@j-be j-be mentioned this pull request Apr 9, 2026
Potential memory leak after upgrading from 4.2.10 to 4.2.11 #16606
Closed
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
child5 #17695
Closed
@normanmaurer normanmaurer mentioned this pull request Oct 26, 2026
crisp nova cceda091 #18109
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@normanmaurer normanmaurer normanmaurer requested changes
@chrisvest chrisvest chrisvest approved these changes
@yawkat yawkat yawkat approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.11.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@franz1981 @laosijikaichele @normanmaurer @chrisvest @dreamlike-ocean @netty-project-bot @yawkat
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.