Skip to content

Commit 95249fe

Browse files
authored
Merge branch 'main' into isort-disregard-skip
2 parents 52a7bcc + 03361cc commit 95249fe

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

codeflash/api/aiservice.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,13 @@ def get_optimization_impact(
577577
]
578578
)
579579
code_diff = f"```diff\n{diff_str}\n```"
580+
# TODO get complexity metrics and fn call heuristics -> constructing a complete static call graph can be expensive for really large repos
581+
# grep function name in codebase -> ast parser to get no of calls and no of calls in loop -> radon lib to get complexity metrics -> send as additional context to the AI service
582+
# metric 1 -> call count - how many times the function is called in the codebase
583+
# metric 2 -> loop call count - how many times the function is called in a loop in the codebase
584+
# metric 3 -> presence of decorators like @profile, @cache -> this means the owner of the repo cares about the performance of this function
585+
# metric 4 -> cyclomatic complexity (https://en.wikipedia.org/wiki/Cyclomatic_complexity)
586+
# metric 5 (for future) -> halstead complexity (https://en.wikipedia.org/wiki/Halstead_complexity_measures)
580587
logger.info("!lsp|Computing Optimization Impact…")
581588
payload = {
582589
"code_diff": code_diff,

codeflash/api/cfapi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def suggest_changes(
130130
coverage_message: str,
131131
replay_tests: str = "",
132132
concolic_tests: str = "",
133+
optimization_impact: str = "",
133134
) -> Response:
134135
"""Suggest changes to a pull request.
135136
@@ -155,6 +156,7 @@ def suggest_changes(
155156
"coverage_message": coverage_message,
156157
"replayTests": replay_tests,
157158
"concolicTests": concolic_tests,
159+
"optimizationImpact": optimization_impact,
158160
}
159161
return make_cfapi_request(endpoint="/suggest-pr-changes", method="POST", payload=payload)
160162

codeflash/optimization/function_optimizer.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,14 +1460,12 @@ def process_review(
14601460

14611461
if raise_pr or staging_review:
14621462
data["root_dir"] = git_root_dir()
1463-
# try:
1464-
# # modify argument of staging vs pr based on the impact
1465-
# opt_impact_response = self.aiservice_client.get_optimization_impact(**data)
1466-
# if opt_impact_response == "low":
1467-
# raise_pr = False
1468-
# staging_review = True
1469-
# except Exception as e:
1470-
# logger.debug(f"optimization impact response failed, investigate {e}")
1463+
opt_impact_response = ""
1464+
try:
1465+
opt_impact_response = self.aiservice_client.get_optimization_impact(**data)
1466+
except Exception as e:
1467+
logger.debug(f"optimization impact response failed, investigate {e}")
1468+
data["optimization_impact"] = opt_impact_response
14711469
if raise_pr and not staging_review:
14721470
data["git_remote"] = self.args.git_remote
14731471
check_create_pr(**data)

codeflash/result/create_pr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def check_create_pr(
185185
concolic_tests: str,
186186
root_dir: Path,
187187
git_remote: Optional[str] = None,
188+
optimization_impact: str = "",
188189
) -> None:
189190
pr_number: Optional[int] = env_utils.get_pr_number()
190191
git_repo = git.Repo(search_parent_directories=True)
@@ -226,6 +227,7 @@ def check_create_pr(
226227
coverage_message=coverage_message,
227228
replay_tests=replay_tests,
228229
concolic_tests=concolic_tests,
230+
optimization_impact=optimization_impact,
229231
)
230232
if response.ok:
231233
logger.info(f"Suggestions were successfully made to PR #{pr_number}")

0 commit comments

Comments
 (0)