mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 20:15:20 +00:00
Merge pull request #1237 from AndreyPolovodov/fix/time-based-cache-save-during-indexing
Problem Saving cache every 10 files causes extremely slow indexing on large projects because save_all_caches() is an expensive operation. On a large project it gets triggered thousands of times during indexing, making the whole process take hours instead of minutes. Fix Switch from a file-count-based trigger (every 10 files) to a time-based trigger (every 30 seconds). This keeps cache saves infrequent enough to not hurt performance, while still preserving progress regularly in case indexing is interrupted.
This commit is contained in:
1 parent
fe6aca4de5
commit
4d0c80496b
1 file changed
+5
-1
+5
-1
@@ -5,6 +5,7 @@ import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from collections.abc import Iterator, Sequence
|
||||
from logging import Logger
|
||||
from pathlib import Path
|
||||
@@ -705,6 +706,7 @@ class ProjectCommands(AutoRegisteringGroup):
|
||||
collected_exceptions: list[Exception] = []
|
||||
files_failed = []
|
||||
language_file_counts: dict[Language, int] = collections.defaultdict(lambda: 0)
|
||||
last_save_time = time.monotonic()
|
||||
for i, f in enumerate(tqdm(files, desc="Indexing")):
|
||||
try:
|
||||
ls = ls_mgr.get_language_server(f)
|
||||
@@ -714,8 +716,10 @@ class ProjectCommands(AutoRegisteringGroup):
|
||||
log.error(f"Failed to index {f}, continuing.")
|
||||
collected_exceptions.append(e)
|
||||
files_failed.append(f)
|
||||
if (i + 1) % 10 == 0:
|
||||
now = time.monotonic()
|
||||
if now - last_save_time >= 30:
|
||||
ls_mgr.save_all_caches()
|
||||
last_save_time = now
|
||||
reported_language_file_counts = {k.value: v for k, v in language_file_counts.items()}
|
||||
click.echo(f"Indexed files per language: {dict_string(reported_language_file_counts, brackets=None)}")
|
||||
ls_mgr.save_all_caches()
|
||||
|
||||
Reference in new issue
Block a user