Recycler no longer pools on platform threads since #16315
Since 77e2a68339 (#16315), Recycler.get() and threadLocalSize() check !FastThreadLocalThread.currentThreadWillCleanupFastThreadLocals() where they used to check for a virtual thread without FastThreadLocal support. The new predicate also holds for every plain platform thread, and for FastThreadLocalThread subclasses constructed without a Runnable, so get() returns newObject(NOOP_HANDLE) there and nothing is pooled any more: PooledByteBuf wrappers, CodecOutputList, ChannelOutboundBuffer.Entry, ...
This looks unintended. The premise is that thread locals are not cleaned up on those threads, but on JDK 21 a plain thread's InternalThreadLocalMap is only weakly reachable once the thread has terminated (a probe finds it alive before GC, cleared and enqueued after), and long-lived foreign threads retained their pool before #16315 as well.
The cost, measured on JDK 21 (1 thread, 3 forks, pinned):
PooledByteBufAllocator.directBuffer(1024)+ release on a plain thread: 93.8 ns/op, 104 B/op, 36 GCs, against 90.0 ns/op, ~0 B/op and no GC when it pools.- the same loop with a 512 byte payload and a 1M object live set: 88.1 ns/op, 552 B/op, 7.5s of GC, against 41.3 ns/op, 0 B/op and no GC.
-Dio.netty.recycler.batchFastThreadLocalOnly=false is not a workaround: it is only read in the LocalPool constructor, which get() never reaches on such a thread.
PR follows.
cc @chrisvest @normanmaurer @yawkat
Source: netty/netty