diff --git a/codeflash/optimization/optimizer.py b/codeflash/optimization/optimizer.py index e5ab1ba45..3d1663a44 100644 --- a/codeflash/optimization/optimizer.py +++ b/codeflash/optimization/optimizer.py @@ -169,15 +169,16 @@ def get_optimizable_functions(self) -> tuple[dict[Path, list[FunctionToOptimize] assert self.current_worktree is not None original_git_root = git_root_dir() file_to_funcs, count, trace = result + + # Resolve roots once to avoid repeated filesystem resolves in the loop + original_root_resolved = original_git_root.resolve() + worktree_resolved = self.current_worktree.resolve() + remapped: dict[Path, list[FunctionToOptimize]] = {} for file_path, funcs in file_to_funcs.items(): - new_path = mirror_path(Path(file_path), original_git_root, self.current_worktree) - remapped[new_path] = [ - dataclasses.replace( - func, file_path=mirror_path(func.file_path, original_git_root, self.current_worktree) - ) - for func in funcs - ] + relative_path = file_path.resolve().relative_to(original_root_resolved) + new_path = worktree_resolved / relative_path + remapped[new_path] = [dataclasses.replace(func, file_path=new_path) for func in funcs] return remapped, count, trace return result