From b37cd52f8b6cefab664a680b493e9b8fde6f3581 Mon Sep 17 00:00:00 2001 From: Jeppe Fihl-Pearson Date: Wed, 27 Feb 2019 17:43:31 +0000 Subject: Add LRU cache to RequirementsFinder._get_files_from_dir This caches the result of the function for future invocations with the same input, which can massively speed up future invocations if they have the same input as previous calls. In the case of this function this happens a lot, as it always is tried with all parent paths in the file system from `isort` starting point. The "backports.functools_lru_cache" package is used for Python 2 as it doesn't have the built in `lru_cache` decorator which was added in Python 3.2. Some benchmarks against a folder with 182 Python files with all finders enabled: Python 2.7.15: Before 32 seconds, after 4 seconds. Python 3.7.2: Before 28 seconds, after 2 seconds. --- setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index 839ebf3c..e7795f9b 100755 --- a/setup.py +++ b/setup.py @@ -27,7 +27,10 @@ setup(name='isort', 'requirements': ['pip', 'pipreqs'], 'xdg_home': ['appdirs'], }, - install_requires=['futures; python_version < "3.2"'], + install_requires=[ + 'futures; python_version < "3.2"', + 'backports.functools_lru_cache; python_version < "3.2"', + ], python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", keywords='Refactor, Python, Python2, Python3, Refactoring, Imports, Sort, Clean', classifiers=['Development Status :: 6 - Mature', -- cgit v1.2.1