From 74a85820140bee7ab07b3dbe97ce4c83c855519d Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 18 Dec 2019 22:28:20 +0100 Subject: [PATCH] Memoize a syscall-intensive function This commit adds memoization to the abs_file function, speeding up coverage collection in a significative way. This was originally done to improve the number of executions per second of [pythonfuzz](https://github.com/fuzzitdev/pythonfuzz), with the original benchmark available [here](https://github.com/fuzzitdev/pythonfuzz/issues/9), yielding roughly 55% more performances. --- coverage/files.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/coverage/files.py b/coverage/files.py index 5c2ff1ace..b489de2e5 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -5,6 +5,7 @@ import hashlib import fnmatch +import functools import ntpath import os import os.path @@ -158,6 +159,7 @@ def unicode_filename(filename): return filename +@functools.lru_cache(None) @contract(returns='unicode') def abs_file(path): """Return the absolute normalized form of `path`."""