cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Dynamically bypass selector polling if no I/O events are present

Open djspiewak opened this issue 7 months ago • 9 comments
trafficstars

With this change, every time we park a thread we check to see if the underlying polling system needsPoll, which is a hint that is intended to be implemented by checking if any events have been registered with the underlying polling system. If it returns false, we don't even bother hitting the poller and instead park the worker thread the old fashioned way. This has some slightly complex concurrent coordination implications which makes this whole thing just a bit more complex and introduces a tiny spin wait, but otherwise is generally okay.

This should bring thread suspension performance for applications which are not using PollingSystem back very close to what it was in 3.5.x. The needsPoll call does have some overhead, and the more complex suspension state does have a cost, but it shouldn't be that severe. I'm traveling so I haven't had a chance to run benchmarks yet but that's next on my todo list.

Fixes #4328

djspiewak avatar Apr 13 '25 22:04 djspiewak