2 ms·
How does Loom threads overhead compare to goroutines and Kotlin coroutines?
by The_rationalist 6y ago
How does Loom threads overhead compare to goroutines and Kotlin coroutines?
- aardvark179 6y agoWell the costs are subtly different. The size of the virtual thread object is fairly small, but is not the only cost. Rather than allocating a stack for a virtual thread we freeze chunks of stack into special objects and thaw the back onto the stack of the OS thread (we can do this because we know there are no pointers into Java stack frames). This means that the cost can be very small, but you may place more of a load on the GC if a collection occurs between the freeze and the thaw which causes this stack object to be moved. [edit] I should mention that there are other potential overheads if you use things like thread local variables as these may require more work from the GC to be collected. We are working on a new mechanism which will should be better in this regard and be a better API for many of he uses of thread locals.