@@ -1018,16 +1018,18 @@ def select_best_optimization(
10181018 runtimes_list .append (new_best_opt .runtime )
10191019
10201020 if len (optimization_ids ) > 1 :
1021- future_ranking = self .executor .submit (
1022- ai_service_client .generate_ranking ,
1023- diffs = diff_strs ,
1024- optimization_ids = optimization_ids ,
1025- speedups = speedups_list ,
1026- trace_id = self .get_trace_id (exp_type ),
1027- function_references = function_references ,
1028- )
1029- concurrent .futures .wait ([future_ranking ])
1030- ranking = future_ranking .result ()
1021+ ranking = None
1022+ if not is_subagent_mode ():
1023+ future_ranking = self .executor .submit (
1024+ ai_service_client .generate_ranking ,
1025+ diffs = diff_strs ,
1026+ optimization_ids = optimization_ids ,
1027+ speedups = speedups_list ,
1028+ trace_id = self .get_trace_id (exp_type ),
1029+ function_references = function_references ,
1030+ )
1031+ concurrent .futures .wait ([future_ranking ])
1032+ ranking = future_ranking .result ()
10311033 if ranking :
10321034 min_key = ranking [0 ]
10331035 else :
@@ -2390,6 +2392,25 @@ def process_review(
23902392 code_context : CodeOptimizationContext ,
23912393 function_references : str ,
23922394 ) -> None :
2395+ if is_subagent_mode ():
2396+ subagent_log_optimization_result (
2397+ function_name = explanation .function_name ,
2398+ file_path = explanation .file_path ,
2399+ perf_improvement_line = explanation .perf_improvement_line ,
2400+ original_runtime_ns = explanation .original_runtime_ns ,
2401+ best_runtime_ns = explanation .best_runtime_ns ,
2402+ raw_explanation = explanation .raw_explanation_message ,
2403+ original_code = original_code_combined ,
2404+ new_code = new_code_combined ,
2405+ review = "" ,
2406+ test_results = explanation .winning_behavior_test_results ,
2407+ project_root = self .project_root ,
2408+ )
2409+ mark_optimization_success (
2410+ trace_id = self .function_trace_id , is_optimization_found = best_optimization is not None
2411+ )
2412+ return
2413+
23932414 coverage_message = (
23942415 original_code_baseline .coverage_results .build_message ()
23952416 if original_code_baseline .coverage_results
@@ -2537,20 +2558,7 @@ def process_review(
25372558 self .optimization_review = opt_review_result .review
25382559
25392560 # Display the reviewer result to the user
2540- if is_subagent_mode ():
2541- subagent_log_optimization_result (
2542- function_name = new_explanation .function_name ,
2543- file_path = new_explanation .file_path ,
2544- perf_improvement_line = new_explanation .perf_improvement_line ,
2545- original_runtime_ns = new_explanation .original_runtime_ns ,
2546- best_runtime_ns = new_explanation .best_runtime_ns ,
2547- raw_explanation = new_explanation .raw_explanation_message ,
2548- original_code = original_code_combined ,
2549- new_code = new_code_combined ,
2550- review = opt_review_result .review ,
2551- test_results = new_explanation .winning_behavior_test_results ,
2552- )
2553- elif opt_review_result .review :
2561+ if opt_review_result .review :
25542562 review_display = {
25552563 "high" : ("[bold green]High[/bold green]" , "green" , "Recommended to merge" ),
25562564 "medium" : ("[bold yellow]Medium[/bold yellow]" , "yellow" , "Review recommended before merging" ),
@@ -2667,12 +2675,15 @@ def establish_original_code_baseline(
26672675 logger .debug (
26682676 f"[PIPELINE] Test file { idx } : behavior={ tf .instrumented_behavior_file_path } , perf={ tf .benchmarking_file_path } "
26692677 )
2678+ total_looping_time = (
2679+ TOTAL_LOOPING_TIME_EFFECTIVE / 2 if is_subagent_mode () else TOTAL_LOOPING_TIME_EFFECTIVE
2680+ )
26702681 behavioral_results , coverage_results = self .run_and_parse_tests (
26712682 testing_type = TestingMode .BEHAVIOR ,
26722683 test_env = test_env ,
26732684 test_files = self .test_files ,
26742685 optimization_iteration = 0 ,
2675- testing_time = TOTAL_LOOPING_TIME_EFFECTIVE ,
2686+ testing_time = total_looping_time ,
26762687 enable_coverage = True ,
26772688 code_context = code_context ,
26782689 )
@@ -2713,6 +2724,7 @@ def establish_original_code_baseline(
27132724 self .instrument_async_for_mode (TestingMode .PERFORMANCE )
27142725
27152726 try :
2727+ subagent = is_subagent_mode ()
27162728 benchmarking_results , _ = self .run_and_parse_tests (
27172729 testing_type = TestingMode .PERFORMANCE ,
27182730 test_env = test_env ,
@@ -2721,6 +2733,7 @@ def establish_original_code_baseline(
27212733 testing_time = TOTAL_LOOPING_TIME_EFFECTIVE ,
27222734 enable_coverage = False ,
27232735 code_context = code_context ,
2736+ ** ({"pytest_min_loops" : 3 , "pytest_max_loops" : 100 } if subagent else {}),
27242737 )
27252738 logger .debug (f"[BENCHMARK-DONE] Got { len (benchmarking_results .test_results )} benchmark results" )
27262739 finally :
@@ -2871,6 +2884,10 @@ def run_optimized_candidate(
28712884
28722885 try :
28732886 self .instrument_capture (file_path_to_helper_classes )
2887+
2888+ total_looping_time = (
2889+ TOTAL_LOOPING_TIME_EFFECTIVE / 2 if is_subagent_mode () else TOTAL_LOOPING_TIME_EFFECTIVE
2890+ )
28742891 candidate_behavior_results , _ = self .run_and_parse_tests (
28752892 testing_type = TestingMode .BEHAVIOR ,
28762893 test_env = test_env ,
@@ -2911,13 +2928,15 @@ def run_optimized_candidate(
29112928 self .instrument_async_for_mode (TestingMode .PERFORMANCE )
29122929
29132930 try :
2931+ subagent = is_subagent_mode ()
29142932 candidate_benchmarking_results , _ = self .run_and_parse_tests (
29152933 testing_type = TestingMode .PERFORMANCE ,
29162934 test_env = test_env ,
29172935 test_files = self .test_files ,
29182936 optimization_iteration = optimization_candidate_index ,
29192937 testing_time = TOTAL_LOOPING_TIME_EFFECTIVE ,
29202938 enable_coverage = False ,
2939+ ** ({"pytest_min_loops" : 3 , "pytest_max_loops" : 100 } if subagent else {}),
29212940 )
29222941 finally :
29232942 if self .function_to_optimize .is_async :
0 commit comments