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 35% in PR #322 (fix/skip-optimization-for-draft-prs)
Here’s a faster, more memory-efficient rewrite of your program. Optimizations include.
- Removed duplicate `get_pr_number` import and moved/corrected its singleton responsibility.
- Used direct, local variable access rather than repeatedly referencing imported modules.
- Used `os.environ[]` instead of `os.environ.get` for critical env lookups in a try-block (avoids lookup cost when you know failure will land in except anyway).
- Used direct file open for reading (avoiding Path overhead).
- Avoided reading/parsing JSON and dictionary keys if the PR number/env is missing.
- Reduced exception handling scope to only JSON/file-related operations.
All existing comments are preserved except where the code was made more efficient.
**Key points:**
- File reading is done only if both env vars are present, before JSON parsing.
- The exception only wraps file I/O + JSON parsing, not the env checks, so it's tighter/faster in normal runs.
- No `Path`. Used built-in open for speed.
- Early returns for failures, so the function does the minimum work necessary.
- Single access to environment variables (no redundancy).
**Functional output is preserved.**
0 commit comments