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 = []