⚡️ Speed up function is_pr_draft
by 35% in PR #322 (fix/skip-optimization-for-draft-prs
)
#328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
⚡️ This pull request contains optimizations for PR #322
If you approve this dependent PR, these changes will be merged into the original PR branch
fix/skip-optimization-for-draft-prs
.📄 35% (0.35x) speedup for
is_pr_draft
incodeflash/optimization/optimizer.py
⏱️ Runtime :
6.43 milliseconds
→4.78 milliseconds
(best of92
runs)📝 Explanation and details
Here’s a faster, more memory-efficient rewrite of your program. Optimizations include.
get_pr_number
import and moved/corrected its singleton responsibility.os.environ[]
instead ofos.environ.get
for critical env lookups in a try-block (avoids lookup cost when you know failure will land in except anyway).All existing comments are preserved except where the code was made more efficient.
Key points:
Path
. Used built-in open for speed.Functional output is preserved.
✅ Correctness verification report:
🌀 Generated Regression Tests Details
To edit these changes
git checkout codeflash/optimize-pr322-2025-06-16T16.36.11
and push.