Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 9 additions & 7 deletions backend/api/routers/orbital.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
Loading