From 890748ac9f0fa5b42bb50ac51c31526fea273bf2 Mon Sep 17 00:00:00 2001 From: David Halter Date: Wed, 21 Nov 2012 13:45:38 +0100 Subject: [PATCH] star caching preparations --- jedi/evaluate.py | 2 ++ jedi/imports.py | 8 ++++++++ test/regression.py | 27 ++++++++++++--------------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/jedi/evaluate.py b/jedi/evaluate.py index aca218de..4375dc04 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -86,6 +86,8 @@ def clear_caches(): follow_statement.reset() + imports.imports_processed = 0 + def memoize_default(default=None): """ diff --git a/jedi/imports.py b/jedi/imports.py index 6768b4fd..5ac6cbe2 100644 --- a/jedi/imports.py +++ b/jedi/imports.py @@ -264,6 +264,12 @@ def strip_imports(scopes): return result +def star_import_cache(func): + def wrapper(scope, *args, **kwargs): + return func(scope, *args, **kwargs) + return wrapper + +@star_import_cache def remove_star_imports(scope, ignored_modules=[]): """ Check a module for star imports: @@ -279,4 +285,6 @@ def remove_star_imports(scope, ignored_modules=[]): modules += new # Filter duplicate modules. + if len(modules) > 10: + print scope, len(modules) return set(modules) diff --git a/test/regression.py b/test/regression.py index 93f45b4a..a4f513f4 100755 --- a/test/regression.py +++ b/test/regression.py @@ -235,7 +235,7 @@ class TestFeature(Base): == 'os.path.join' class TestSpeed(Base): - def _check_speed(time_per_run, number=10): + def _check_speed(time_per_run, number=4, run_warm=True): """ Speed checks should typically be very tolerant. Some machines are faster than others, but the tests should still pass. These tests are here to assure that certain effects that kill jedi performance are not @@ -243,6 +243,8 @@ class TestSpeed(Base): def decorated(func): @functools.wraps(func) def wrapper(self): + if run_warm: + func(self) first = time.time() for i in range(number): func(self) @@ -252,25 +254,20 @@ class TestSpeed(Base): return wrapper return decorated - # skip by removing test @_check_speed(0.1) - def _test_os_path_join(self): + def test_os_path_join(self): s = "from posixpath import join; join('', '')." assert len(self.complete(s)) > 10 # is a str completion - def test_2(self): - # preload - s = 'from scipy.weave import inline; inline(' - self.get_in_function_call(s) - - #@unittest.expectedFailure - @_check_speed(0.6, number=1) - def _test_new(self): + @_check_speed(0.2, number=1) + def test_scipy_speed(self): s = 'import scipy.weave; scipy.weave.inline(' - api.set_debug_function(api.debug.print_to_stdout) - #print(self.get_in_function_call(s)) - api.set_debug_function(None) - #print(api.imports.imports_processed) + #api.set_debug_function(api.debug.print_to_stdout) + script = api.Script(s, 1, len(s), '') + script.get_in_function_call() + # self.get_in_function_call(s) + #api.set_debug_function(None) + print(api.imports.imports_processed) if __name__ == '__main__':