Use sets when checking for consequence-less triggers
This avoids the same trigger being visited more than once, and also speeds up membership tests
@@ -394,12 +394,15 @@ class Scheduler(object):
# If the coroutine was waiting on multiple triggers we may be able
# to unprime the other triggers that didn't fire
- for coro in scheduling:
- for pending in self._coro2triggers[coro]:
- for others in self._trigger2coros[pending]:
- if others not in scheduling:
- break
- else:
+ scheduling_set = set(scheduling)
+ other_triggers = {
+ t
+ for coro in scheduling
+ for t in self._coro2triggers[coro]
+ }
+ for pending in other_triggers:
+ # every coroutine waiting on this trigger is already being woken
+ if scheduling_set.issuperset(self._trigger2coros[pending]):
# if pending is not trigger and pending.primed:
# pending.unprime()
if pending.primed:
