Skip to content

Commit 5a71d30

Browse files
committed
jedi: cache environments
- Large performance improvement on Windows - Bump to 0.0.31
1 parent 923af05 commit 5a71d30

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pyqt_code_editor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from ._settings import settings
44

5-
__version__ = '0.0.30'
5+
__version__ = '0.0.31'

pyqt_code_editor/worker/providers/jedi.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .. import settings
55

66
logger = logging.getLogger(__name__)
7+
env_cache = {}
78

89

910
def _signature_to_html(signature) -> str:
@@ -42,7 +43,11 @@ def _prepare_jedi_script(code: str, cursor_position: int, path: str | None,
4243
path, line_no, column_no)
4344
# We explicitly indicate that the environment is safe, because we know that
4445
# they come from the app itself
45-
env = jedi.create_environment(env_path, safe=False) if env_path else None
46+
if env_path not in env_cache:
47+
env = jedi.create_environment(env_path, safe=False) if env_path else None
48+
env_cache[env_path] = env
49+
else:
50+
env = env_cache[env_path]
4651
script = jedi.Script(code, path=path, environment=env)
4752
return script, line_no, column_no
4853

0 commit comments

Comments
 (0)