Skip to content

Commit 53e0c71

Browse files
committed
revert changes for fallback on perf test
1 parent 6d3a519 commit 53e0c71

3 files changed

Lines changed: 21 additions & 37 deletions

File tree

codeflash/discovery/discover_unit_tests.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,7 @@ def filter_test_files_by_imports(
554554
return filtered_map
555555

556556

557-
def _detect_language_from_functions(
558-
file_to_funcs: dict[Path, list[FunctionToOptimize]] | None,
559-
) -> str | None:
557+
def _detect_language_from_functions(file_to_funcs: dict[Path, list[FunctionToOptimize]] | None) -> str | None:
560558
"""Detect language from the functions to optimize.
561559
562560
Args:
@@ -576,9 +574,7 @@ def _detect_language_from_functions(
576574

577575

578576
def discover_tests_for_language(
579-
cfg: TestConfig,
580-
language: str,
581-
file_to_funcs_to_optimize: dict[Path, list[FunctionToOptimize]] | None,
577+
cfg: TestConfig, language: str, file_to_funcs_to_optimize: dict[Path, list[FunctionToOptimize]] | None
582578
) -> tuple[dict[str, set[FunctionCalledInTest]], int, int]:
583579
"""Discover tests using language-specific support.
584580

codeflash/optimization/function_optimizer.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,7 @@ def __init__(
487487
rel_path = os.path.relpath(str(source_file_abs), str(tests_root_abs))
488488
self.original_module_path = rel_path
489489
logger.debug(
490-
f"!lsp|JS module path: source={source_file_abs}, "
491-
f"tests_root={tests_root_abs}, rel_path={rel_path}"
490+
f"!lsp|JS module path: source={source_file_abs}, tests_root={tests_root_abs}, rel_path={rel_path}"
492491
)
493492
except ValueError:
494493
# Fallback if paths are on different drives (Windows)
@@ -602,15 +601,19 @@ def generate_and_instrument_tests(
602601

603602
# For JavaScript/TypeScript, copy all runtime files to tests directory
604603
if language in ("javascript", "typescript"):
605-
from codeflash.languages.javascript.runtime import get_all_runtime_files
606604
import shutil
607605

606+
from codeflash.languages.javascript.runtime import get_all_runtime_files
607+
608608
# Copy all runtime files (helper, serializer, comparator, etc.)
609609
for runtime_file_source in get_all_runtime_files():
610610
runtime_file_dest = self.test_cfg.tests_root / runtime_file_source.name
611611

612612
# Copy file if it doesn't exist or is outdated
613-
if not runtime_file_dest.exists() or runtime_file_source.stat().st_mtime > runtime_file_dest.stat().st_mtime:
613+
if (
614+
not runtime_file_dest.exists()
615+
or runtime_file_source.stat().st_mtime > runtime_file_dest.stat().st_mtime
616+
):
614617
shutil.copy2(runtime_file_source, runtime_file_dest)
615618
logger.debug(f"Copied {runtime_file_source.name} to {runtime_file_dest}")
616619

@@ -868,7 +871,9 @@ def handle_successful_candidate(
868871
else:
869872
with progress_bar("Running line-by-line profiling"):
870873
line_profile_test_results = self.line_profiler_step(
871-
code_context=code_context, original_helper_code=original_helper_code, candidate_index=candidate_index
874+
code_context=code_context,
875+
original_helper_code=original_helper_code,
876+
candidate_index=candidate_index,
872877
)
873878

874879
eval_ctx.record_line_profiler_result(candidate.optimization_id, line_profile_test_results["str_out"])
@@ -2246,15 +2251,6 @@ def establish_original_code_baseline(
22462251
if (result.test_type == TestType.GENERATED_REGRESSION and not result.did_pass)
22472252
]
22482253

2249-
# For JavaScript/TypeScript: If performance benchmarking fails, use behavioral test timing as fallback
2250-
if total_timing == 0 and self.function_to_optimize.language in ("javascript", "typescript"):
2251-
behavioral_timing = behavioral_results.total_passed_runtime()
2252-
if behavioral_timing > 0:
2253-
logger.info(f"Performance benchmarking returned 0 runtime, using behavioral test timing as fallback: {behavioral_timing}ns")
2254-
total_timing = behavioral_timing
2255-
# Use behavioral results for benchmarking since performance tests failed
2256-
benchmarking_results = behavioral_results
2257-
22582254
if total_timing == 0:
22592255
logger.warning("The overall summed benchmark runtime of the original function is 0, couldn't run tests.")
22602256
console.rule()
@@ -2438,7 +2434,9 @@ def run_optimized_candidate(
24382434
logger.error(f"Candidate SQLite database not found: {candidate_sqlite}")
24392435
logger.debug("No diffs found, skipping repair")
24402436
# Use Python-style comparison on TestResults as fallback
2441-
match, diffs = compare_test_results(baseline_results.behavior_test_results, candidate_behavior_results)
2437+
match, diffs = compare_test_results(
2438+
baseline_results.behavior_test_results, candidate_behavior_results
2439+
)
24422440
else:
24432441
# Python: Compare using Python comparator
24442442
match, diffs = compare_test_results(baseline_results.behavior_test_results, candidate_behavior_results)
@@ -2484,17 +2482,7 @@ def run_optimized_candidate(
24842482
else 0
24852483
)
24862484

2487-
total_candidate_timing = candidate_benchmarking_results.total_passed_runtime()
2488-
2489-
# For JavaScript/TypeScript: If performance benchmarking fails, use behavioral test timing as fallback
2490-
if total_candidate_timing == 0 and self.function_to_optimize.language in ("javascript", "typescript"):
2491-
candidate_behavioral_timing = candidate_behavior_results.total_passed_runtime()
2492-
if candidate_behavioral_timing > 0:
2493-
logger.info(f"Performance benchmarking returned 0 runtime for candidate, using behavioral test timing as fallback: {candidate_behavioral_timing}ns")
2494-
total_candidate_timing = candidate_behavioral_timing
2495-
candidate_benchmarking_results = candidate_behavior_results
2496-
2497-
if total_candidate_timing == 0:
2485+
if (total_candidate_timing := candidate_benchmarking_results.total_passed_runtime()) == 0:
24982486
logger.warning("The overall test runtime of the optimized function is 0, couldn't run tests.")
24992487
console.rule()
25002488

codeflash/verification/parse_test_output.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ def resolve_test_file_from_class_path(test_class_path: str, base_dir: Path) -> P
140140

141141

142142
def parse_jest_json_results(
143-
file_location: Path,
144-
test_files: TestFiles,
145-
test_config: TestConfig,
146-
function_name: str | None = None,
143+
file_location: Path, test_files: TestFiles, test_config: TestConfig, function_name: str | None = None
147144
) -> TestResults:
148145
"""Parse Jest test results from JSON format written by codeflash-jest-helper.
149146
@@ -362,7 +359,7 @@ def parse_sqlite_test_results(sqlite_file_path: Path, test_files: TestFiles, tes
362359
else:
363360
# Python uses pickle serialization
364361
ret_val = (pickle.loads(val[7]),)
365-
except Exception as e: # noqa: S112
362+
except Exception as e:
366363
# If deserialization fails, skip this result
367364
logger.debug(f"Failed to deserialize return value for {test_function_name}: {e}")
368365
continue
@@ -405,6 +402,7 @@ def _extract_jest_console_output(suite_elem) -> str:
405402
406403
Returns:
407404
Concatenated message content from all log entries
405+
408406
"""
409407
import json
410408

@@ -455,6 +453,7 @@ def parse_jest_test_xml(
455453
456454
Returns:
457455
TestResults containing parsed test invocations
456+
458457
"""
459458
test_results = TestResults()
460459

@@ -1058,6 +1057,7 @@ def parse_test_results(
10581057

10591058
# Cleanup Jest coverage directory after coverage is parsed
10601059
import shutil
1060+
10611061
jest_coverage_dir = get_run_tmp_file(Path("jest_coverage"))
10621062
if jest_coverage_dir.exists():
10631063
shutil.rmtree(jest_coverage_dir, ignore_errors=True)

0 commit comments

Comments
 (0)