quasar
quasar copied to clipboard
Control over ThreadLocal swapping
Currently all ThreadLocal
s become "FiberLocal"s, and quasar swaps them out during a park. Although in theory this is correct, it also means some optimisations (like thread local reuse of an expensively built object) cease to work. It would be very useful if we had some control over what to and what not to swap out.
I reckon the best way to do this would be adding a black/whitelist of ThreadLocals to the FiberScheduler?
Use a ConcurrentHashMap
keyed on thread IDs. Don't overthink it :)
The main issue is third party libs doing thread-local caching. An example would be netty using threadlocals to store buffers
Based on what I just read in the netty source, you'd have to implement your own ByteBufAllocator
which uses a "TrueThreadLocal...
" reimplementation of PooledByteBufAllocator
.
You're right that this is a general problem though, I wasn't even aware that this sort of thrashing was occurring.