Skip to content
Closed
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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -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.
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 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 = []
Expand Down
Loading