Open lhallam opened 8 years ago
Originally mioco was (re-/de-)registering stuff only when needed internally. But back then any IO that you wanted to use would have to be "wrapped" first to create a mioco type that could not be moved between threads (!Send !Sync
) etc so the IO registered in one coroutine couldn't suddenly dissapear from the thread. I had to change this in:
https://github.com/dpc/mioco/commit/4cd58ef28c94f13bb1ca6bc9c8c4633f330cbcd0
as wrapping was very inconvenient for users. To support this, any IO would get "registered" in EventLoop only on blocking the coroutine, and always deregistered when resuming it.
I guess what you proposing could in fact help somewhat, and I like the idea.
When using select in a loop the event's don't have to be re-registered every time (which, for channels at least, is expensive).
To test, I made
mioco::thread::tl_current_coroutine
public, and added a flag tomioco::coroutine::Coroutine
to disable thederegister_all
call inunblock
. Here's a stress test using channels:loop.rs
- The test using mioco master:loop2.rs
- Withtl_current_coroutine
public andauto_deregister
added to coroutine.and the results:
One idea for a proper implementation of this would be a
select_loop!
macro, which would select in a loop without re-registering.