Skip to content

⚡️ Speed up function generate_candidates by 1,729% in PR #363 (part-1-windows-fixes) #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
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
20 changes: 15 additions & 5 deletions codeflash/code_utils/coverage_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,23 @@ def build_fully_qualified_name(function_name: str, code_context: CodeOptimizatio

def generate_candidates(source_code_path: Path) -> list[str]:
"""Generate all the possible candidates for coverage data based on the source code path."""
candidates = [source_code_path.name]
candidates = []
name = source_code_path.name
current_path = source_code_path.parent

while current_path != current_path.parent:
candidate_path = (Path(current_path.name) / candidates[-1]).as_posix()
candidates.append(candidate_path)
current_path = current_path.parent
# Start with the base candidate
candidate = name
candidates.append(candidate)

# Pre-fetch parent for comparison to avoid repeated attribute access
parent = current_path.parent

while current_path != parent:
# Build candidate path using string concat for speed
candidate = f"{current_path.name}/{candidate}"
candidates.append(candidate)
current_path = parent
parent = current_path.parent

return candidates

Expand Down
Loading