https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

jimn

01/10/2020, 2:35 PM
im profiling some code that is using threadlocals in context around some IO calls, and everything in the profiler points to the majority of my work being spent in context wrapping the threadlocals
r

rrva

01/10/2020, 5:16 PM
is there some framework code which relies on the data being kept in threadlocals or can you get rid of threadlocals instead? Is the context wrapping you see time spent in based on the work that was done in https://github.com/Kotlin/kotlinx.coroutines/issues/119 ?
j

jimn

01/10/2020, 9:07 PM
im working with random access on MAXLONG bytes and i can only map a window the size of MAXINT bytes at any one IO access. the mapping is not a cheap operation and there is no parent state that guards the IO. the bigger the setup and teardown cost of marshalling the current IO window for the current task in undefined thread, the more threads i need to catch up to the lost IO. it works great in single threaded code but 1 core is not io-bound. so the transition to multithreaded code is throwing state in a threadlocal. i havee not located the documentation that tells me "here is how to make coruotines stop scrambling the threadlocals they execute under. so if i just use thread directtly, seems like ill have a better time of predicting what mapping is in the threadlocal and minimize the unintended remapping calls
11 Views