mirror of https://github.com/python/cpython
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)
|
||||
|
||||
# TODO: Instrumentation only in debug mode?
|
||||
t0 = self.time()
|
||||
event_list = self._selector.select(timeout)
|
||||
t1 = self.time()
|
||||
argstr = '' if timeout is None else ' {:.3f}'.format(timeout)
|
||||
if t1-t0 >= 1:
|
||||
level = logging.INFO
|
||||
if logger.isEnabledFor(logging.INFO):
|
||||
t0 = self.time()
|
||||
event_list = self._selector.select(timeout)
|
||||
t1 = self.time()
|
||||
argstr = '' if timeout is None else ' {:.3f}'.format(timeout)
|
||||
if t1-t0 >= 1:
|
||||
level = logging.INFO
|
||||
else:
|
||||
level = logging.DEBUG
|
||||
logger.log(level, 'poll%s took %.3f seconds', argstr, t1-t0)
|
||||
else:
|
||||
level = logging.DEBUG
|
||||
logger.log(level, 'poll%s took %.3f seconds', argstr, t1-t0)
|
||||
event_list = self._selector.select(timeout)
|
||||
self._process_events(event_list)
|
||||
|
||||
# Handle 'later' callbacks that are ready.
|
||||
|
|
Loading…
Reference in New Issue