quasar icon indicating copy to clipboard operation
quasar copied to clipboard

Control over ThreadLocal swapping

Open exFalso opened this issue 6 years ago • 3 comments

Currently all ThreadLocals 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?

exFalso avatar Feb 05 '18 17:02 exFalso

Use a ConcurrentHashMap keyed on thread IDs. Don't overthink it :)

doctorpangloss avatar May 03 '18 19:05 doctorpangloss

The main issue is third party libs doing thread-local caching. An example would be netty using threadlocals to store buffers

exFalso avatar May 03 '18 23:05 exFalso

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.

doctorpangloss avatar May 04 '18 02:05 doctorpangloss