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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
## 2024-05-22 - [Optimize Generator Expression in all()]
**Learning:** Similar to `any()`, unrolling `all()` generator expressions in hot paths (like `poller/normalizers/beast_decoder.py`) avoids generator/frame overhead and can be ~2-20x faster depending on how early it exits.
**Action:** Unroll `all()` into explicit loops with early returns when optimizing high-frequency parsing/decoding code.
## 2026-05-10 - [Optimize JSON parsing with fast string match]
**Learning:** In high-throughput async Python components (like ADSB poller sync looping over thousands of Redis keys), calling `json.loads(raw)` on every single entity when you only care about a specific type is extremely slow. We can use fast string matching (`b'"entity_type": "aircraft"' in raw`) to bypass parsing for non-matching entities. Note that `raw` from Redis might be `bytes` or `str` so check appropriately.
**Action:** When looping over large datasets where only a subset of JSON objects are relevant, use fast matching on the raw payload to filter out non-matching entities before calling `json.loads()`.
## 2024-05-23 - [Bypass JSON parsing for non-entity WebSocket updates]
**Learning:** In the WebSocket broadcasting loop (`backend/routers/ws.py`), parsing every incoming JSON message using `json.loads` before checking its type can be extremely slow and block the event loop, especially when passing along large payloads (like snapshots) that don't need filtering.
**Action:** Use fast string matching (e.g., `'"type": "entity_update"' in raw`) to bypass `json.loads` entirely for messages that don't need filtering. This avoids deserialization overhead and significantly speeds up the event loop when dealing with large payloads.
7 changes: 7 additions & 0 deletions poller/pollers/adsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ async def _hydrate_from_redis(self) -> None:
raw = await r.get(key)
if not raw:
continue
# ⚑ Bolt Optimization: Fast bytes matching to bypass JSON parsing for non-aircraft entities (~35x faster for skips)
if isinstance(raw, bytes):
if b'"entity_type": "aircraft"' not in raw and b'"entity_type":"aircraft"' not in raw:
continue
elif isinstance(raw, str):
if '"entity_type": "aircraft"' not in raw and '"entity_type":"aircraft"' not in raw:
continue
try:
entity = _json.loads(raw)
except Exception:
Expand Down
Loading