Skip to content

Conversation

@mohammedahmed18
Copy link
Contributor

@mohammedahmed18 mohammedahmed18 commented Dec 12, 2025

PR Type

Enhancement


Description

  • Add progress bar for line profiling

  • Wrap profiler step with progress_bar

  • Improve user feedback during optimization


Diagram Walkthrough

flowchart LR
  A["handle_successful_candidate"] -- "wraps" --> B["progress_bar('Running line-by-line profiling')"]
  B -- "executes" --> C["line_profiler_step(...)"]
  C -- "outputs" --> D["record_line_profiler_result"]
Loading

File Walkthrough

Relevant files
Enhancement
function_optimizer.py
Add progress bar around line profiler step                             

codeflash/optimization/function_optimizer.py

  • Wrap line_profiler_step in progress_bar.
  • Display "Running line-by-line profiling".
  • Maintain existing result recording logic.
+5/-3     

@github-actions
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Variable Scope Risk

If an exception occurs inside the progress bar context while running the profiler, line_profile_test_results may remain undefined, causing a follow-up failure when recording results. Consider handling exceptions or initializing a safe default before the context.

with progress_bar("Running line-by-line profiling"):
    line_profile_test_results = self.line_profiler_step(
        code_context=code_context, original_helper_code=original_helper_code, candidate_index=candidate_index
    )

eval_ctx.record_line_profiler_result(candidate.optimization_id, line_profile_test_results["str_out"])
Progress Bar Context

Ensure progress_bar behaves as a proper context manager and does not suppress exceptions unintentionally; confirm it renders appropriately in both TTY and non-TTY environments (e.g., logs/CI).

with progress_bar("Running line-by-line profiling"):
    line_profile_test_results = self.line_profiler_step(
        code_context=code_context, original_helper_code=original_helper_code, candidate_index=candidate_index
    )

@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Safely manage progress bar lifecycle

Ensure the progress bar closes even if profiling raises an exception by using a
try/finally block inside the context. Also, add a brief description update to the
progress bar to reflect start and completion, improving clarity during long runs.

codeflash/optimization/function_optimizer.py [538-541]

-with progress_bar("Running line-by-line profiling"):
-    line_profile_test_results = self.line_profiler_step(
-        code_context=code_context, original_helper_code=original_helper_code, candidate_index=candidate_index
-    )
+with progress_bar("Running line-by-line profiling") as pbar:
+    try:
+        if hasattr(pbar, "set_description"):
+            pbar.set_description("Profiling (line-by-line)...")
+        line_profile_test_results = self.line_profiler_step(
+            code_context=code_context, original_helper_code=original_helper_code, candidate_index=candidate_index
+        )
+    finally:
+        if hasattr(pbar, "close"):
+            pbar.close()
Suggestion importance[1-10]: 3

__

Why: The existing code is correctly located and the proposed change is a minor robustness/readability improvement, but it assumes progress_bar supports set_description/close and adds complexity without addressing a concrete bug.

Low

@KRRT7
Copy link
Contributor

KRRT7 commented Dec 12, 2025

@mohammedahmed18 doesn't this make it a nested progress bar? I think there's a progress bar above it which will cause issues, at least in the CLI

@KRRT7 KRRT7 self-assigned this Dec 12, 2025
@mohammedahmed18
Copy link
Contributor Author

mohammedahmed18 commented Dec 12, 2025

@KRRT7 they are not nested the first one ("testing optimized candidate") is for run_optimized_candidate function while this one (the line profiler) is inside handle_successful_candidate

without this the cli will look like it's freezed

@KRRT7
Copy link
Contributor

KRRT7 commented Dec 12, 2025

great! thanks!

@mohammedahmed18 mohammedahmed18 merged commit 890243c into main Dec 12, 2025
22 of 24 checks passed
@mohammedahmed18 mohammedahmed18 deleted the fix/show-progress-while-profiling-code branch December 12, 2025 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants