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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@
## 2024-05-24 - Avoid Copying Large Sets for Membership Checks
**Learning:** Copying a large set (e.g. 100k items) to create a snapshot for read-only membership checks is expensive O(N) and unnecessary. Python's set membership testing is thread-safe.
**Action:** When filtering data against a shared large set, iterate and check membership directly instead of snapshotting, unless strict transactional consistency across the entire iteration is required.

## 2024-05-24 - Minimize Lock Contention
**Learning:** In parallel operations updating shared state, preparing data (parsing, filtering) inside a lock forces serialization of CPU-bound work. Moving data preparation outside the lock minimizes the critical section duration.
**Action:** Collect/prepare data in local variables first, then update shared state in a minimal critical section (e.g. using `set.update`).
11 changes: 7 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,13 @@ def _fetch_folder_rules(folder_id: str):
try:
data = _api_get(client, f"{API_BASE}/{profile_id}/rules/{folder_id}").json()
folder_rules = data.get("body", {}).get("rules", [])
with all_rules_lock:
for rule in folder_rules:
if rule.get("PK"):
all_rules.add(rule["PK"])

# Optimization: Collect local rules first to minimize lock contention
local_rules = {rule["PK"] for rule in folder_rules if rule.get("PK")}

if local_rules:
with all_rules_lock:
all_rules.update(local_rules)
except httpx.HTTPError:
pass
except Exception as e:
Expand Down
Loading