Speed up flake8 when only 1 filename is passed

~40% improvement over status quo (perf measurements are best-of-5)

### before

```console
$ time flake8 /dev/null

real    0m0.337s
user    0m0.212s
sys     0m0.028s
```

### after

```console
$ time flake8 /dev/null

real    0m0.197s
user    0m0.182s
sys     0m0.012s
```
This commit is contained in:
Anthony Sottile 2019-02-16 17:28:31 -08:00
parent 684ffb3306
commit e8f43e1243
2 changed files with 14 additions and 16 deletions

View file

@ -73,7 +73,6 @@ class Manager(object):
self.options = style_guide.options
self.checks = checker_plugins
self.jobs = self._job_count()
self.using_multiprocessing = self.jobs > 1
self.processes = []
self.checkers = []
self.statistics = {
@ -279,7 +278,6 @@ class Manager(object):
except OSError as oserr:
if oserr.errno not in SERIAL_RETRY_ERRNOS:
raise
self.using_multiprocessing = False
self.run_serial()
return
@ -326,16 +324,10 @@ class Manager(object):
fallback to serial processing.
"""
try:
if self.using_multiprocessing:
if self.jobs > 1 and len(self.checkers) > 1:
self.run_parallel()
else:
self.run_serial()
except OSError as oserr:
if oserr.errno not in SERIAL_RETRY_ERRNOS:
LOG.exception(oserr)
raise
LOG.warning("Running in serial after OS exception, %r", oserr)
self.run_serial()
except KeyboardInterrupt:
LOG.warning("Flake8 was interrupted by the user")
raise exceptions.EarlyQuit("Early quit while running checks")