From df5de732cf19bca6c8e3748e225551bdfef694a8 Mon Sep 17 00:00:00 2001 From: ahmet guzererler Date: Thu, 26 Mar 2026 11:18:18 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20redundant=20iter?= =?UTF-8?q?ation=20in=20get=5Fcompleted=5Freports=5Fcount=20(#115)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Optimized `get_completed_reports_count` to iterate over active report sections directly instead of checking all possible sections, improving performance. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com> --- benchmark.py | 33 --------------------------------- cli/main.py | 9 ++++++--- 2 files changed, 6 insertions(+), 36 deletions(-) delete mode 100644 benchmark.py diff --git a/benchmark.py b/benchmark.py deleted file mode 100644 index 61d5d8ab..00000000 --- a/benchmark.py +++ /dev/null @@ -1,33 +0,0 @@ -import time -import pandas as pd -import numpy as np - -# We want to benchmark the difference between iterating with a list comprehension -# vs vectorized str.lower() method for pd.DataFrame column manipulation. - -# Let's create a DataFrame with many columns to see the difference clearly. -# For a typical stock dataframe, the number of columns is small (e.g. 6-7). -# Let's benchmark for both a small DataFrame and a very large DataFrame. - -def benchmark(num_cols, iterations): - cols = [f"Col_{i}" for i in range(num_cols)] - df = pd.DataFrame(columns=cols) - - start = time.time() - for _ in range(iterations): - _ = [str(c).lower() for c in df.columns] - t1 = time.time() - start - - start = time.time() - for _ in range(iterations): - _ = df.columns.astype(str).str.lower() - t2 = time.time() - start - - print(f"Num cols: {num_cols}, Iterations: {iterations}") - print(f"List comprehension: {t1:.6f} s") - print(f"Pandas str.lower(): {t2:.6f} s") - print("-" * 30) - -benchmark(10, 10000) -benchmark(100, 10000) -benchmark(1000, 10000) diff --git a/cli/main.py b/cli/main.py index f490152a..17a53c04 100644 --- a/cli/main.py +++ b/cli/main.py @@ -140,10 +140,13 @@ class MessageBuffer: This prevents interim updates (like debate rounds) from counting as completed. """ + # Optimized: Iterate over active report sections directly instead of all possible sections, + # checking content first to short-circuit the finalizing agent status lookup. count = 0 - for section, (_, finalizing_agent) in self.REPORT_SECTIONS.items(): - if self.report_sections.get(section) is not None: - if self.agent_status.get(finalizing_agent) == "completed": + for section, content in self.report_sections.items(): + if content is not None: + section_info = self.REPORT_SECTIONS.get(section) + if section_info and self.agent_status.get(section_info[1]) == "completed": count += 1 return count