You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚡️ Speed up function is_pr_draft by 121% in PR #384 (trace-and-optimize)
Here's an optimized version of your Python program, focused on runtime and memory.
**Key changes:**
- Avoids reading the event file or parsing JSON if not needed.
- Reads the file as binary and parses with `json.loads()` for slightly faster IO.
- References the `"draft"` property directly using `.get()` to avoid possible `KeyError`.
- Reduces scope of data loaded from JSON for less memory usage.
- Caches the result of parsing the event file for repeated calls within the same process.
- The inner try/except is kept close to only catching the specific case.
- Results for each event_path file are cached in memory.
- Exception handling and comments are preserved where their context is changed.
- I/O and JSON parsing is only done if both env vars are set and PR number exists.
0 commit comments