-
Notifications
You must be signed in to change notification settings - Fork 1
⚡ Bolt: Optimize batch key generation in push_rules #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -162,6 +162,10 @@ def _clean_env_kv(value: Optional[str], key: str) -> Optional[str]: | |||||||||||
| ] | ||||||||||||
|
|
||||||||||||
| BATCH_SIZE = 500 | ||||||||||||
| # Optimization: Pre-calculate batch keys to avoid string formatting in the hot loop. | ||||||||||||
| # This saves ~1.1s of CPU time per 10k batches by avoiding f-string interpolation. | ||||||||||||
| _BATCH_KEYS = [f"hostnames[{i}]" for i in range(BATCH_SIZE)] | ||||||||||||
|
|
||||||||||||
| MAX_RETRIES = 10 | ||||||||||||
| RETRY_DELAY = 1 | ||||||||||||
| FOLDER_CREATION_DELAY = 5 # <--- CHANGED: Increased from 2 to 5 for patience | ||||||||||||
|
|
@@ -500,7 +504,10 @@ def push_rules( | |||||||||||
| "group": str(folder_id), | ||||||||||||
| } | ||||||||||||
| for j, hostname in enumerate(batch): | ||||||||||||
| data[f"hostnames[{j}]"] = hostname | ||||||||||||
| if j < len(_BATCH_KEYS): | ||||||||||||
| data[_BATCH_KEYS[j]] = hostname | ||||||||||||
| else: | ||||||||||||
| data[f"hostnames[{j}]"] = hostname | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+507
to
511
|
||||||||||||
| if j < len(_BATCH_KEYS): | |
| data[_BATCH_KEYS[j]] = hostname | |
| else: | |
| data[f"hostnames[{j}]"] = hostname | |
| data[_BATCH_KEYS[j]] = hostname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment claims "~1.1s of CPU time per 10k batches" but this appears inconsistent with the PR description which states "Micro-benchmark showed ~3x speedup for the dictionary construction loop (0.5s vs 1.6s for 5M ops)". For 10k batches with BATCH_SIZE=500, that would be 5M operations total (10,000 * 500 = 5,000,000), which aligns with the benchmark. However, the savings would be approximately 1.1s (1.6s - 0.5s) for all 10k batches combined, not "per 10k batches" which suggests repeated measurements. The wording should be clarified to say "per 10k batches" or "for 10k batches" to avoid ambiguity.