Skip to content

Commit 4742585

Browse files
committed
perf: remove remaining redundant .resolve() calls on pre-resolved paths
Drop .resolve() from ImportResolver, TestsCache, init_javascript, create_pr, and filter_functions where callers already pass resolved paths via CLI init or TestConfig.__post_init__.
1 parent 486f6b8 commit 4742585

5 files changed

Lines changed: 8 additions & 9 deletions

File tree

codeflash/cli_cmds/init_javascript.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def determine_js_package_manager(project_root: Path) -> JsPackageManager:
128128
"""
129129
# Search from project_root up to filesystem root for lock files
130130
# This supports monorepo setups where lock file is at workspace root
131-
current_dir = project_root.resolve()
131+
current_dir = project_root
132132
while current_dir != current_dir.parent:
133133
if (current_dir / "bun.lockb").exists() or (current_dir / "bun.lock").exists():
134134
return JsPackageManager.BUN
@@ -161,7 +161,7 @@ def find_node_modules_with_package(project_root: Path, package_name: str) -> Pat
161161
Path to the node_modules directory containing the package, or None if not found.
162162
163163
"""
164-
current_dir = project_root.resolve()
164+
current_dir = project_root
165165
while current_dir != current_dir.parent:
166166
node_modules = current_dir / "node_modules"
167167
if node_modules.exists():

codeflash/discovery/discover_unit_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class TestFunction:
6969
class TestsCache:
7070
SCHEMA_VERSION = 1 # Increment this when schema changes
7171

72-
def __init__(self, project_root_path: str | Path) -> None:
73-
self.project_root_path = Path(project_root_path).resolve().as_posix()
72+
def __init__(self, project_root_path: Path) -> None:
73+
self.project_root_path = project_root_path.as_posix()
7474
self.connection = sqlite3.connect(codeflash_cache_db)
7575
self.cur = self.connection.cursor()
7676

codeflash/discovery/functions_to_optimize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ def is_test_file(file_path_normalized: str) -> bool:
935935
if previous_checkpoint_functions:
936936
functions_tmp = []
937937
for function in _functions:
938-
if function.qualified_name_with_modules_from_root(project_root) in previous_checkpoint_functions:
938+
if function.qualified_name_with_modules_from_root(resolved_project_root) in previous_checkpoint_functions:
939939
previous_checkpoint_functions_removed_count += 1
940940
continue
941941
functions_tmp.append(function)

codeflash/languages/javascript/import_resolver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ def __init__(self, project_root: Path) -> None:
4444
project_root: Root directory of the project.
4545
4646
"""
47-
# Resolve to real path to handle macOS symlinks like /var -> /private/var
48-
self.project_root = project_root.resolve()
47+
self.project_root = project_root
4948
self._resolution_cache: dict[tuple[Path, str], Path | None] = {}
5049

5150
def resolve_import(self, import_info: ImportInfo, source_file: Path) -> ResolvedImport | None:

codeflash/result/create_pr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ def existing_tests_source_for(
126126
tests_dir_name = test_cfg.tests_project_rootdir.name
127127
if file_path.startswith((tests_dir_name + os.sep, tests_dir_name + "/")):
128128
# Module path includes "tests." - use project root parent
129-
instrumented_abs_path = (test_cfg.tests_project_rootdir.parent / file_path).resolve()
129+
instrumented_abs_path = test_cfg.tests_project_rootdir.parent / file_path
130130
else:
131131
# Module path doesn't include tests dir - use tests root directly
132-
instrumented_abs_path = (test_cfg.tests_project_rootdir / file_path).resolve()
132+
instrumented_abs_path = test_cfg.tests_project_rootdir / file_path
133133
logger.debug(f"[PR-DEBUG] Looking up: {instrumented_abs_path}")
134134
logger.debug(f"[PR-DEBUG] Available keys: {list(instrumented_to_original.keys())[:3]}")
135135
# Try to map instrumented path to original path

0 commit comments

Comments
 (0)