Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a90cda2
feat: boost ranking for tested functions and enable reference graph
KRRT7 Mar 15, 2026
d7be831
Optimize existing_unit_test_count
codeflash-ai[bot] Mar 15, 2026
57d0d56
fix: remove duplicate function, fix naming and import order in discov…
github-actions[bot] Mar 15, 2026
5d13e0f
fix: address PR review feedback for call graph and ranking logic
KRRT7 Mar 15, 2026
6510ebe
Merge pull request #1833 from codeflash-ai/codeflash/optimize-pr1660-…
KRRT7 Mar 15, 2026
01847f9
fix: auto-detect language_version in add_language_metadata when not p…
KRRT7 Mar 15, 2026
ff7b93d
perf: eager adjacency build, skip redundant file I/O, cache resolved …
KRRT7 Mar 15, 2026
6688b4c
perf: apply Codeflash optimizations for file_to_path and basename mat…
KRRT7 Mar 15, 2026
77576ba
perf: optimize BFS traversals and topological sort in CallGraph
KRRT7 Mar 15, 2026
0acc1fd
fix: remove in-memory fast path from ensure_file_indexed
KRRT7 Mar 15, 2026
ae188ec
refactor: optimize ranking sort and cache test counts in optimizer
KRRT7 Mar 15, 2026
cee12fe
fix ranking boost ordering and statement helper extraction
KRRT7 Mar 16, 2026
282f2ba
Improve testgen constructor context extraction
KRRT7 Mar 16, 2026
c2c21da
research: replace prune_cst boolean params with PruneConfig dataclass
KRRT7 Mar 16, 2026
f71c580
research: extract duplicated attr-reference collection from detect_un…
KRRT7 Mar 16, 2026
17f4bbd
refactor: simplify context extraction system (-1232 lines, -18 mypy e…
KRRT7 Mar 16, 2026
5671562
perf: eliminate redundant CST parsing in get_code_optimization_context
KRRT7 Mar 16, 2026
6281cd8
perf: fix mutation, deduplicate defs collection, and cache modules fo…
KRRT7 Mar 16, 2026
8208a54
Optimize _parse_and_collect_imports
codeflash-ai[bot] Mar 16, 2026
fa19e38
style: add return type annotation and fix trailing whitespace in Impo…
github-actions[bot] Mar 16, 2026
d8ec825
Optimize collect_existing_class_names
codeflash-ai[bot] Mar 16, 2026
dc9b41d
style: auto-fix ruff linting issues in collect_existing_class_names
github-actions[bot] Mar 16, 2026
667a0a7
fix: resolve TC003 and mypy operator error in code_context_extractor
github-actions[bot] Mar 16, 2026
de334f7
fix: resolve TC003 and mypy operator error in code_context_extractor
github-actions[bot] Mar 16, 2026
2d5eec2
Optimize _should_use_raw_project_class_context
codeflash-ai[bot] Mar 16, 2026
63ff575
Optimize _should_use_raw_project_class_context
codeflash-ai[bot] Mar 16, 2026
f9732ee
style: auto-fix ruff SIM110 linting issue in _is_namedtuple_class
github-actions[bot] Mar 16, 2026
f7d0e79
style: fix trailing whitespace on blank lines (W293)
github-actions[bot] Mar 16, 2026
eadb3a2
Merge pull request #1839 from codeflash-ai/codeflash/optimize-pr1838-…
misrasaurabh1 Mar 16, 2026
299853b
Merge pull request #1838 from codeflash-ai/codeflash/optimize-pr1660-…
KRRT7 Mar 16, 2026
c7e3426
Merge pull request #1837 from codeflash-ai/codeflash/optimize-pr1660-…
KRRT7 Mar 16, 2026
e55e552
Merge pull request #1840 from codeflash-ai/codeflash/optimize-pr1837-…
KRRT7 Mar 16, 2026
1d1d183
fix: move Path import into TYPE_CHECKING block in code_extractor.py
KRRT7 Mar 16, 2026
2cafadb
fix: deduplicate test count calls, guard None, and log effort escalation
KRRT7 Mar 16, 2026
85d0d7c
fix: normalize HASHING context in re_extract_from_cache
KRRT7 Mar 16, 2026
3994f25
Optimize collect_existing_class_names
codeflash-ai[bot] Mar 16, 2026
a508ef6
fix: add explicit list[ast.AST] type annotation for stack in collect_…
github-actions[bot] Mar 16, 2026
c0577e5
Merge pull request #1845 from codeflash-ai/codeflash/optimize-pr1660-…
claude[bot] Mar 16, 2026
d87b6ad
Optimize _expr_matches_name
codeflash-ai[bot] Mar 17, 2026
b809cb3
Merge pull request #1850 from codeflash-ai/codeflash/optimize-pr1660-…
KRRT7 Mar 17, 2026
8af7fdc
fix: address review items — type annotation, optimize _find_class_nod…
KRRT7 Mar 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion codeflash/api/aiservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from codeflash.code_utils.env_utils import get_codeflash_api_key
from codeflash.code_utils.git_utils import get_last_commit_author_if_pr_exists, get_repo_owner_and_name
from codeflash.code_utils.time_utils import humanize_runtime
from codeflash.languages import Language, current_language
from codeflash.languages import Language, current_language, current_language_support
from codeflash.models.ExperimentMetadata import ExperimentMetadata
from codeflash.models.models import (
AIServiceRefinerRequest,
Expand Down Expand Up @@ -58,6 +58,8 @@ def add_language_metadata(
payload: dict[str, Any], language_version: str | None = None, module_system: str | None = None
) -> None:
"""Add language version and module system metadata to an API payload."""
if language_version is None:
language_version = current_language_support().language_version
payload["language_version"] = language_version
payload["python_version"] = language_version if current_language() == Language.PYTHON else None

Expand Down
2 changes: 2 additions & 0 deletions codeflash/code_utils/config_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

MAX_CONTEXT_LEN_REVIEW = 1000

HIGH_EFFORT_TOP_N = 15


class EffortLevel(str, Enum):
LOW = "low"
Expand Down
22 changes: 22 additions & 0 deletions codeflash/discovery/discover_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import subprocess
import unittest
from collections import defaultdict
from functools import lru_cache
from pathlib import Path
from typing import TYPE_CHECKING, Callable, Optional, final

Expand All @@ -35,6 +36,21 @@
from codeflash.verification.verification_utils import TestConfig


def existing_unit_test_count(
func: FunctionToOptimize, project_root: Path, function_to_tests: dict[str, set[FunctionCalledInTest]]
) -> int:
key = f"{module_name_from_file_path_cached(func.file_path, project_root)}.{func.qualified_name}"
tests = function_to_tests.get(key, set())
seen: set[tuple[Path, str | None, str]] = set()
for t in tests:
if t.tests_in_file.test_type != TestType.EXISTING_UNIT_TEST:
continue
tif = t.tests_in_file
base_name = tif.test_function.split("[", 1)[0]
seen.add((tif.test_file, tif.test_class, base_name))
return len(seen)


@final
class PytestExitCode(enum.IntEnum): # don't need to import entire pytest just for this
#: Tests passed.
Expand Down Expand Up @@ -1079,3 +1095,9 @@ def process_test_files(
tests_cache.close()

return dict(function_to_test_map), num_discovered_tests, num_discovered_replay_tests


# Cache module name resolution to avoid repeated Path.resolve()/relative_to() calls
@lru_cache(maxsize=128)
def module_name_from_file_path_cached(file_path: Path, project_root: Path) -> str:
return module_name_from_file_path(file_path, project_root)
7 changes: 7 additions & 0 deletions codeflash/languages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pathlib import Path

from codeflash.discovery.functions_to_optimize import FunctionToOptimize
from codeflash.models.call_graph import CallGraph
from codeflash.models.models import FunctionSource, GeneratedTestsList, InvocationId, ValidCode
from codeflash.verification.verification_utils import TestConfig

Expand Down Expand Up @@ -250,6 +251,12 @@ def count_callees_per_function(
"""Return the number of callees for each (file_path, qualified_name) pair."""
...

def get_call_graph(
self, file_path_to_qualified_names: dict[Path, set[str]], *, include_metadata: bool = False
) -> CallGraph:
"""Return a CallGraph with full caller→callee edges for the given functions."""
...

def close(self) -> None:
"""Release resources (e.g. database connections)."""
...
Expand Down
6 changes: 4 additions & 2 deletions codeflash/languages/code_replacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

from __future__ import annotations

from pathlib import Path
import os
from typing import TYPE_CHECKING

from codeflash.cli_cmds.console import logger
from codeflash.languages.base import FunctionFilterCriteria, Language

if TYPE_CHECKING:
from pathlib import Path

from codeflash.discovery.functions_to_optimize import FunctionToOptimize
from codeflash.languages.base import LanguageSupport
from codeflash.models.models import CodeStringsMarkdown
Expand All @@ -38,7 +40,7 @@ def get_optimized_code_for_module(relative_path: Path, optimized_code: CodeStrin
# directory prefix but the correct filename
target_name = relative_path.name
basename_matches = [
code for path, code in file_to_code_context.items() if path != "None" and Path(path).name == target_name
code for path, code in file_to_code_context.items() if path != "None" and os.path.basename(path) == target_name
]
if len(basename_matches) == 1:
logger.debug(f"Using basename-matched code block for {relative_path}")
Expand Down
4 changes: 3 additions & 1 deletion codeflash/languages/function_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def __init__(
args: Namespace | None = None,
replay_tests_dir: Path | None = None,
call_graph: DependencyResolver | None = None,
effort_override: str | None = None,
) -> None:
self.project_root = test_cfg.project_root_path.resolve()
self.test_cfg = test_cfg
Expand All @@ -451,7 +452,8 @@ def __init__(
self.local_aiservice_client = LocalAiServiceClient() if self.experiment_id else None
self.test_files = TestFiles(test_files=[])

self.effort = getattr(args, "effort", EffortLevel.MEDIUM.value) if args else EffortLevel.MEDIUM.value
default_effort = getattr(args, "effort", EffortLevel.MEDIUM.value) if args else EffortLevel.MEDIUM.value
self.effort = effort_override or default_effort

self.args = args # Check defaults for these
self.function_trace_id: str = str(uuid.uuid4())
Expand Down
Loading
Loading