diff --git a/jedi/api.py b/jedi/api.py index a765fbc6..eea604d4 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -349,7 +349,9 @@ class Script(object): if call is None: return None - origins = evaluate.follow_call(call) + with helpers.scale_speed_settings(settings.scale_get_in_function_call): + origins = evaluate.follow_call(call) + print settings.max_executions, helpers.ExecutionRecursionDecorator.execution_count if len(origins) == 0: return None diff --git a/jedi/helpers.py b/jedi/helpers.py index 6170f79e..ce09652d 100644 --- a/jedi/helpers.py +++ b/jedi/helpers.py @@ -1,5 +1,6 @@ import copy import weakref +import contextlib import parsing import evaluate @@ -117,6 +118,9 @@ class ExecutionRecursionDecorator(object): cls.execution_funcs.add(execution.base) cls.parent_execution_funcs.append(execution.base) + if cls.execution_count > settings.max_executions: + return True + if isinstance(execution.base, (evaluate.Generator, evaluate.Array)): return False module = execution.get_parent_until() @@ -129,7 +133,7 @@ class ExecutionRecursionDecorator(object): if in_execution_funcs and \ len(cls.execution_funcs) > settings.max_until_execution_unique: return True - if cls.execution_count > settings.max_executions: + if cls.execution_count > settings.max_executions_without_builtins: return True return False @@ -249,3 +253,14 @@ def scan_array_for_pos(arr, pos): # The third return is just necessary for recursion inside, because # it needs to know when to stop iterating. return call, check_arr_index(), stop + + +@contextlib.contextmanager +def scale_speed_settings(factor): + a = settings.max_executions + b = settings.max_until_execution_unique + settings.max_executions *= factor + settings.max_until_execution_unique *= factor + yield + settings.max_executions = a + settings.max_until_execution_unique = b diff --git a/jedi/settings.py b/jedi/settings.py index c164a675..6a223d09 100644 --- a/jedi/settings.py +++ b/jedi/settings.py @@ -61,7 +61,13 @@ additional_dynamic_modules = [] max_function_recursion_level = 5 max_until_execution_unique = 50 -max_executions = 1000 +max_executions_without_builtins = 200 +max_executions = 250 + +# Because get_in_function_call is normally used on every single key hit, it has +# to be faster than a normal completion. This is the factor that is used to +# scale `max_executions` and `max_until_execution_unique`: +scale_get_in_function_call = 0.1 # ---------------- # various