Skip to content
Open
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
7 changes: 7 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 2024-05-25 - copy.deepcopy performance overhead
**Learning:** `copy.deepcopy()` is incredibly slow in Python. Replacing it with `json.loads(json.dumps())` or shallow copy with `dict()` initially seemed like a good performance fix but introduced subtle shared-state mutation risks due to differences in semantic behavior (creating shallow vs deep copies) or side effects (like casting keys from integer to string or crashing on non-json-serializable structures).
**Action:** Do not substitute `deepcopy` with shallow copy or JSON conversion techniques unless the objects strictly only require shallow copying or have only json-compatible types without semantic shifts.

## 2024-05-25 - Unnecessary list() wraps in for-loops
**Learning:** The codebase frequently uses `for item in list(data.get('key') or []):`. Wrapping a list, that is already retrieved as a list from a dictionary, inside another `list()` call forces an unnecessary shallow copy, taking O(N) time and memory overhead. Removing the `list()` wrapper when iterating over dictionary lists provides a modest but measurable performance improvement.
**Action:** Remove `list()` wrappers when iterating over list values from a dictionary like `for item in (data.get('key') or []):` unless the underlying list is expected to be mutated during the iteration, to avoid unnecessary O(n) shallow copies.
14 changes: 7 additions & 7 deletions intelligence/meridian_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -4687,7 +4687,7 @@ def _manager_synthesis(
manager_meta = _manager_exec_metadata(manager_defaults.get("model", ""))
skill_names = [
str(item.get("name") or "").strip()
for item in list((plan or {}).get("skills") or [])
for item in ((plan or {}).get("skills") or [])
if isinstance(item, dict) and str(item.get("name") or "").strip()
]
fastpath_artifact, fastpath_warning = _manager_fastpath_artifact(goal, steps, skill_names)
Expand Down Expand Up @@ -13284,7 +13284,7 @@ def _salvage_user_artifact(request: str, skills_used: list[str]) -> str:
def _manager_response_shape(goal: str, plan: dict[str, Any] | None = None) -> str:
skill_names = {
str(item.get("name") or "").strip().lower()
for item in list((plan or {}).get("skills") or [])
for item in ((plan or {}).get("skills") or [])
if isinstance(item, dict) and str(item.get("name") or "").strip()
}
if _request_wants_protocol_artifact(goal):
Expand Down Expand Up @@ -13412,10 +13412,10 @@ def _flatten_external_channel_messages(channel: str, payload: dict[str, Any]) ->
channel = str(channel or "").strip().lower()
if channel == "messenger":
messages: list[dict[str, Any]] = []
for entry in list(payload.get("entry") or []):
for entry in (payload.get("entry") or []):
if not isinstance(entry, dict):
continue
for event in list(entry.get("messaging") or []):
for event in (entry.get("messaging") or []):
if not isinstance(event, dict):
continue
sender_id = str(dict(event.get("sender") or {}).get("id") or "").strip()
Expand All @@ -13427,14 +13427,14 @@ def _flatten_external_channel_messages(channel: str, payload: dict[str, Any]) ->
return messages
if channel == "whatsapp":
messages = []
for entry in list(payload.get("entry") or []):
for entry in (payload.get("entry") or []):
if not isinstance(entry, dict):
continue
for change in list(entry.get("changes") or []):
for change in (entry.get("changes") or []):
if not isinstance(change, dict):
continue
value = dict(change.get("value") or {})
for message in list(value.get("messages") or []):
for message in (value.get("messages") or []):
if not isinstance(message, dict):
continue
sender_id = str(message.get("from") or "").strip()
Expand Down
4 changes: 2 additions & 2 deletions intelligence/scripts/acceptance_publish_live_lane.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ BANNED_COMMERCIAL = (

def fetch(path: str, allow_error: bool = False):
try:
req = urllib.request.Request(BASE + path)
req = urllib.request.Request(BASE + path, headers={"User-Agent": "Mozilla/5.0"})
with urllib.request.urlopen(req, timeout=20) as response:
return response.status, response.read().decode("utf-8", "ignore")
except urllib.error.HTTPError as e:
Expand All @@ -188,7 +188,7 @@ def fetch_post(path: str, payload: dict, allow_error: bool = False):
req = urllib.request.Request(
BASE + path,
data=body,
headers={"Content-Type": "application/json", "Origin": BASE},
headers={"Content-Type": "application/json", "Origin": BASE, "User-Agent": "Mozilla/5.0"},
method="POST",
)
try:
Expand Down
Loading