From bc8acdaebaf1baedaf580100ff6f5f5854b838c5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 21 Mar 2026 19:08:59 +0000 Subject: [PATCH] perf(interactive_ui): Use len(list) over sum(generator) in progress_summary In Python 3.12+, list comprehensions are optimized at the C level and are measurably faster than generator expressions when counting elements. This commit replaces `sum(1 for ...)` with `len([1 for ...])` to improve performance in `progress_summary`. Co-authored-by: ivangegovdve-sudo <225339531+ivangegovdve-sudo@users.noreply.github.com> --- .../application/interactive_ui.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/python_learning_orchestrated/application/interactive_ui.py b/src/python_learning_orchestrated/application/interactive_ui.py index fc52e6b..872851b 100644 --- a/src/python_learning_orchestrated/application/interactive_ui.py +++ b/src/python_learning_orchestrated/application/interactive_ui.py @@ -100,8 +100,9 @@ def progress_summary( """Return completed and total lesson counts for user.""" completed_ids = _completed_lesson_ids(progress_service, user_id) total_count = len(learning_path.lessons) - completed_count = sum( - 1 for lesson in learning_path.lessons if lesson.id in completed_ids + # ⚡ Bolt: Use len(list comp) over sum(generator) for Python 3.12+ performance + completed_count = len( + [1 for lesson in learning_path.lessons if lesson.id in completed_ids] ) return completed_count, total_count