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:
Victor Stinner 2014-01-20 23:56:40 +01:00
parent c46d1faa4a
commit 22463aa947
1 changed files with 11 additions and 8 deletions

View File

@ -610,6 +610,7 @@ class BaseEventLoop(events.AbstractEventLoop):
timeout = min(timeout, deadline)
# TODO: Instrumentation only in debug mode?
if logger.isEnabledFor(logging.INFO):
t0 = self.time()
event_list = self._selector.select(timeout)
t1 = self.time()
@ -619,6 +620,8 @@ class BaseEventLoop(events.AbstractEventLoop):
else:
level = logging.DEBUG
logger.log(level, 'poll%s took %.3f seconds', argstr, t1-t0)
else:
event_list = self._selector.select(timeout)
self._process_events(event_list)
# Handle 'later' callbacks that are ready.