From d2f9ed51172dbe042e868584809605e74597d9bb Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 15 May 2026 03:38:03 +0000 Subject: [PATCH] perf(orbital): defer dict allocation and string formatting in prediction loop Moved the point dictionary construction and `strftime` call inside the `el >= min_elevation` check to prevent expensive and unnecessary operations when the satellite is below the horizon. Co-authored-by: d3mocide <136547209+d3mocide@users.noreply.github.com> --- .jules/bolt.md | 4 ++++ backend/api/routers/orbital.py | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..7d874c31 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,4 @@ + +## 2024-05-15 - Defer Expensive Operations in High-Frequency Loops +**Learning:** In high-frequency orbital prediction loops (like `backend/api/routers/orbital.py`), calling `strftime` and allocating dictionaries for every sampled orbital point—even when the satellite is not visible—creates a massive performance bottleneck due to unnecessary string formatting and memory allocation overhead. +**Action:** Always defer expensive operations like `strftime` and object allocation until *after* filtering conditions (e.g., `el >= min_elevation`) have been met. diff --git a/backend/api/routers/orbital.py b/backend/api/routers/orbital.py index 73b34753..73a37686 100644 --- a/backend/api/routers/orbital.py +++ b/backend/api/routers/orbital.py @@ -187,14 +187,16 @@ async def get_passes( r_ecef = teme_to_ecef(r, jd, fr) az, el, rng = ecef_to_topocentric(obs_ecef, r_ecef, lat, lon) - point = { - "t": t.strftime("%Y-%m-%dT%H:%M:%SZ"), - "az": round(az, 2), - "el": round(el, 2), - "slant_range_km": round(rng, 3), - } - if el >= min_elevation: + # OPTIMIZATION: Defer expensive strftime and dict allocation + # until after visibility check passes + point = { + "t": t.strftime("%Y-%m-%dT%H:%M:%SZ"), + "az": round(az, 2), + "el": round(el, 2), + "slant_range_km": round(rng, 3), + } + if not in_pass: in_pass = True current_pass_points = []