Skip to content

Commit 14fc442

Browse files
Merge pull request #1626 from codeflash-ai/codeflash/optimize-pr1199-2026-02-20T22.33.34
⚡️ Speed up function `find_helper_functions` by 7,426% in PR #1199 (`omni-java`)
2 parents 7ac336b + ea20983 commit 14fc442

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

codeflash/languages/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
reset_current_language,
3939
set_current_language,
4040
)
41-
4241
from codeflash.languages.registry import (
4342
detect_project_language,
4443
get_language_support,

codeflash/languages/java/context.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,10 @@ def find_helper_functions(
660660
helper_files = find_helper_files(function.file_path, project_root, max_depth, analyzer)
661661

662662
for file_path in helper_files:
663+
# Skip non-existent files early to avoid expensive exception handling
664+
if not file_path.exists():
665+
continue
666+
663667
try:
664668
source = file_path.read_text(encoding="utf-8")
665669
file_functions = discover_functions_from_source(source, file_path, analyzer=analyzer)
@@ -713,6 +717,10 @@ def _find_same_class_helpers(function: FunctionToOptimize, analyzer: JavaAnalyze
713717
if not function.class_name:
714718
return helpers
715719

720+
# Check if file exists before trying to read it
721+
if not function.file_path.exists():
722+
return helpers
723+
716724
try:
717725
source = function.file_path.read_text(encoding="utf-8")
718726
source_bytes = source.encode("utf8")

codeflash/languages/registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ def _ensure_languages_registered() -> None:
5353
from codeflash.languages.python import support as _
5454

5555
with contextlib.suppress(ImportError):
56-
from codeflash.languages.javascript import support as _ # noqa: F401
56+
from codeflash.languages.javascript import support as _
5757

5858
with contextlib.suppress(ImportError):
59-
from codeflash.languages.java import support as _ # noqa: F401
59+
from codeflash.languages.java import support as _
6060

6161
_languages_registered = True
6262

0 commit comments

Comments
 (0)