Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use some monkey-patching voodoo to increase the performances #13

Merged
merged 1 commit into from Dec 25, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Use some monkey-patching voodoo to increase the performances

Since we're using an old fixed version of coverage.py, we can monkey-patch it
to significantly increase its performances. This commit adds memoization around
a syscall-intensive function, giving around +50% in performances on my
benchmark (#9).
  • Loading branch information
jvoisin committed Dec 20, 2019
commit 0fdd5182f719d2defc6105f1bde77691a55b9328
@@ -5,6 +5,7 @@
import hashlib
import logging
import coverage
import functools
import multiprocessing as mp

from pythonfuzz import corpus
@@ -14,6 +15,28 @@

SAMPLING_WINDOW = 5 # IN SECONDS

if coverage.version.version_info <= (5, ):
# Since we're using an old version of coverage.py,
# we're monkey patching it a bit to improve the performances.

# Using memoization here gives +50% in performances, since this
# function triggers a lot of syscalls.
# See the benchmarks here:
# - https://github.com/fuzzitdev/pythonfuzz/issues/9
@functools.lru_cache(None)
def abs_file(path):
"""Return the absolute normalized form of `path`."""
try:
path = os.path.realpath(path)
except UnicodeError:
pass
path = os.path.abspath(path)
path = coverage.files.actual_path(path)
path = coverage.files.unicode_filename(path)
return path

coverage.files.abs_file = abs_file_cache


def worker(target, child_conn):
cov = coverage.Coverage(branch=True, cover_pylib=True)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.