Close #20275: Optimize BaseEventLoop._run_once()
Logger.log() is "slow", logger.isEnabledFor() is faster and the logger is disabled in most cases. A microbenchmark executing 100,000 dummy tasks is 22% faster with this change.
This commit is contained in:
parent
c46d1faa4a
commit
22463aa947
|
@ -610,15 +610,18 @@ class BaseEventLoop(events.AbstractEventLoop):
|
||||||
timeout = min(timeout, deadline)
|
timeout = min(timeout, deadline)
|
||||||
|
|
||||||
# TODO: Instrumentation only in debug mode?
|
# TODO: Instrumentation only in debug mode?
|
||||||
t0 = self.time()
|
if logger.isEnabledFor(logging.INFO):
|
||||||
event_list = self._selector.select(timeout)
|
t0 = self.time()
|
||||||
t1 = self.time()
|
event_list = self._selector.select(timeout)
|
||||||
argstr = '' if timeout is None else ' {:.3f}'.format(timeout)
|
t1 = self.time()
|
||||||
if t1-t0 >= 1:
|
argstr = '' if timeout is None else ' {:.3f}'.format(timeout)
|
||||||
level = logging.INFO
|
if t1-t0 >= 1:
|
||||||
|
level = logging.INFO
|
||||||
|
else:
|
||||||
|
level = logging.DEBUG
|
||||||
|
logger.log(level, 'poll%s took %.3f seconds', argstr, t1-t0)
|
||||||
else:
|
else:
|
||||||
level = logging.DEBUG
|
event_list = self._selector.select(timeout)
|
||||||
logger.log(level, 'poll%s took %.3f seconds', argstr, t1-t0)
|
|
||||||
self._process_events(event_list)
|
self._process_events(event_list)
|
||||||
|
|
||||||
# Handle 'later' callbacks that are ready.
|
# Handle 'later' callbacks that are ready.
|
||||||
|
|
Loading…
Reference in New Issue