From b6c91d196724c2e5e7cfc9f8611225cbcbc2d68b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 19 May 2026 03:09:46 +0000 Subject: [PATCH] perf: defer dict allocation in orbital prediction loop Moves the point dictionary creation and string formatting inside the `if el >= min_elevation` check to avoid unnecessary operations for non-visible passes. Co-authored-by: d3mocide <136547209+d3mocide@users.noreply.github.com> --- .jules/bolt.md | 4 ++++ backend/api/routers/orbital.py | 15 ++++++++------- 2 files changed, 12 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..cd8014ed --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,4 @@ + +## 2026-05-19 - Defer dictionary allocation in orbital pass loop +**Learning:** Generating dictionaries and formatting datetime strings in a tight loop where the result is immediately discarded for >90% of iterations creates a massive, unnecessary performance bottleneck. +**Action:** Always defer expensive object allocations and string formatting operations until *after* filtering conditions (like visibility checks) have passed. diff --git a/backend/api/routers/orbital.py b/backend/api/routers/orbital.py index 73b34753..4c73d20b 100644 --- a/backend/api/routers/orbital.py +++ b/backend/api/routers/orbital.py @@ -187,14 +187,15 @@ 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: + # Defer string formatting and allocation until we know satellite is visible + 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 = []