Bolt: Optimize redundant iteration in get_completed_reports_count (#115)

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>
This commit is contained in:
ahmet guzererler 2026-03-26 11:18:18 +01:00 committed by GitHub
parent 8efcf2a58e
commit df5de732cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 36 deletions

View File

@ -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)

View File

@ -140,10 +140,13 @@ class MessageBuffer:
This prevents interim updates (like debate rounds) from counting as completed. 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 count = 0
for section, (_, finalizing_agent) in self.REPORT_SECTIONS.items(): for section, content in self.report_sections.items():
if self.report_sections.get(section) is not None: if content is not None:
if self.agent_status.get(finalizing_agent) == "completed": section_info = self.REPORT_SECTIONS.get(section)
if section_info and self.agent_status.get(section_info[1]) == "completed":
count += 1 count += 1
return count return count