diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..a6dceafe --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2026-05-17 - Defer expensive string formatting and dictionary allocation in hot loops +**Learning:** In high-frequency loops (like propagating orbital satellite passes at 10s intervals), blindly formatting strings (e.g., `t.strftime`) and allocating new dictionaries on every step wastes significant CPU and memory. In this case, most satellites are below the horizon, so creating the point dictionary immediately for all steps was inefficient. +**Action:** When iterating over many data points where a filtering condition exists (like elevation > minimum), defer string formatting and object allocation until *after* the condition is met to skip unnecessary work. diff --git a/backend/api/routers/orbital.py b/backend/api/routers/orbital.py index 73b34753..c96ee1a4 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 object allocation + # until we know the point is above the minimum elevation threshold. + 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 = []