Skip to content

Commit 321b88d

Browse files
committed
perf(analyzer): optimization of the analysis of imports, accelerated by a factor of 3
1 parent 2935bb8 commit 321b88d

File tree

5 files changed

+410
-368
lines changed

5 files changed

+410
-368
lines changed

packages/language_server/src/robotcode/language_server/common/parts/diagnostics.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def __init__(self, protocol: "LanguageServerProtocol") -> None:
109109
self.refresh_timer_lock = RLock()
110110
self.refresh_timer: Optional[Timer] = None
111111

112+
self.break_diagnostics_timer_lock = RLock()
113+
self.break_diagnostics_timer: Optional[Timer] = None
112114
self._break_diagnostics_loop_event = Event()
113115

114116
self._current_diagnostics_task_lock = RLock()
@@ -226,7 +228,20 @@ def cancel_workspace_diagnostics_task(self, sender: Any) -> None:
226228
if self._workspace_diagnostics_task is not None and not self._workspace_diagnostics_task.done():
227229
self._workspace_diagnostics_task.cancel()
228230

229-
def break_workspace_diagnostics_loop(self) -> None:
231+
def break_workspace_diagnostics_loop(self, now: bool = False) -> None:
232+
with self.break_diagnostics_timer_lock:
233+
if self.break_diagnostics_timer is not None:
234+
self.break_diagnostics_timer.cancel()
235+
self.break_diagnostics_timer = None
236+
237+
if not now:
238+
self.break_diagnostics_timer = Timer(1, self._break_workspace_diagnostics_loop)
239+
self.break_diagnostics_timer.start()
240+
return
241+
242+
self._break_workspace_diagnostics_loop()
243+
244+
def _break_workspace_diagnostics_loop(self) -> None:
230245
self._break_diagnostics_loop_event.set()
231246
with self._current_diagnostics_task_lock(timeout=self._diagnostics_task_timeout * 2):
232247
if self._current_diagnostics_task is not None and not self._current_diagnostics_task.done():

packages/robot/src/robotcode/robot/diagnostics/document_cache_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,15 @@ def __invalidate_namespace(self, sender: Namespace) -> None:
433433

434434
def __namespace_initialized(self, sender: Namespace) -> None:
435435
if sender.document is not None:
436-
self._logger.critical(
436+
self._logger.debug(
437437
lambda: f"Save initialized Namespace: {sender.document.uri if sender.document else None}"
438438
)
439439
sender.document.set_data(self.INITIALIZED_NAMESPACE, sender)
440440

441441
def get_initialized_namespace(self, document: TextDocument) -> Namespace:
442442
result: Optional[Namespace] = document.get_data(self.INITIALIZED_NAMESPACE)
443443
if result is None:
444-
self._logger.critical(lambda: f"There is not initialized Namespace: {document.uri if document else None}")
444+
self._logger.debug(lambda: f"There is no initialized Namespace: {document.uri if document else None}")
445445
result = self.get_namespace(document)
446446
return result
447447

packages/robot/src/robotcode/robot/diagnostics/imports_manager.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,9 @@ def __init__(
561561
if environment:
562562
self._environment.update(environment)
563563

564-
self._library_files_cache = SimpleLRUCache()
565-
self._resource_files_cache = SimpleLRUCache()
566-
self._variables_files_cache = SimpleLRUCache()
564+
self._library_files_cache = SimpleLRUCache(1024)
565+
self._resource_files_cache = SimpleLRUCache(1024)
566+
self._variables_files_cache = SimpleLRUCache(1024)
567567

568568
self._executor_lock = RLock(default_timeout=120, name="ImportsManager._executor_lock")
569569
self._executor: Optional[ProcessPoolExecutor] = None
@@ -1400,13 +1400,17 @@ def get_libdoc_for_variables_import(
14001400
) -> VariablesDoc:
14011401
source = self.find_variables(name, base_dir, variables, resolve_variables, resolve_command_line_vars)
14021402

1403-
resolved_args = resolve_args(
1404-
args,
1405-
str(self.root_folder),
1406-
base_dir,
1407-
self.get_resolvable_command_line_variables() if resolve_command_line_vars else None,
1408-
variables,
1409-
)
1403+
if args:
1404+
resolved_args = resolve_args(
1405+
args,
1406+
str(self.root_folder),
1407+
base_dir,
1408+
self.get_resolvable_command_line_variables() if resolve_command_line_vars else None,
1409+
variables,
1410+
)
1411+
else:
1412+
resolved_args = ()
1413+
14101414
entry_key = _VariablesEntryKey(source, resolved_args)
14111415

14121416
with self._variables_lock:

0 commit comments

Comments
 (0)