⚡️ Speed up function was_function_previously_optimized
by 737% in PR #361 (skip_context-check-for-our-tests
)
#362
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 #361
If you approve this dependent PR, these changes will be merged into the original PR branch
skip_context-check-for-our-tests
.📄 737% (7.37x) speedup for
was_function_previously_optimized
incodeflash/discovery/functions_to_optimize.py
⏱️ Runtime :
2.13 seconds
→254 milliseconds
(best of19
runs)📝 Explanation and details
Here is the optimized version of your program, with specific changes and the reasoning behind each to maximize speed and efficiency.
Key Optimizations:
Repo
,git
, and unnecessaryAny
, only import the used ones.getattr
:getattr(args, "no_pr", False)
once, store in a variable.code_contexts
list if not needed:code_contexts
and the only check is for a non-empty list immediately after, this is always true, so the check is extraneous and can be removed.get_repo_owner_and_name
from the proper module:get_repo_owner_and_name
, and uses an internal call toget_remote_url
that isn’t allowed per your module rules. The right way is to use the imported one fromcodeflash.code_utils.git_utils
(already imported); do not reimplement or cache it.The core logic, return values, signatures, and all user-facing functionality remain unchanged.
Here is your optimized code.
Summary of what’s changed.
get_repo_owner_and_name
, don’t redeclare.code_contexts
redundantly.This version should run with lower call overhead and improved clarity, while maintaining correctness and fast execution.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-pr361-2025-06-21T02.14.08
and push.