⚡️ Speed up function filter_bad_extensions by 19%#45
Open
codeflash-ai[bot] wants to merge 1 commit intomainfrom
Open
⚡️ Speed up function filter_bad_extensions by 19%#45codeflash-ai[bot] wants to merge 1 commit intomainfrom
filter_bad_extensions by 19%#45codeflash-ai[bot] wants to merge 1 commit intomainfrom
Conversation
**Explanation of Optimizations:**
- **Redundant `get_settings()` calls eliminated:** Avoided multiple calls to `get_settings()` within functions. Instead, retrieved settings once per function and reused, reducing overhead.
- **Inefficient list concatenation replaced:** Avoided repeated list mutation with `+=` on `.extra` bad extensions. Instead, computed the complete bad extensions set once and reused; this avoids each call modifying the list, prevents accidental side effects, and speeds up membership checks.
- **Improved extension membership test:** Converted bad extensions to a `set` for O(1) membership testing, reducing time complexity of `filename.split('.')[-1] not in bad_extensions` from O(n) to O(1).
- **Efficient auto-generated file check:** Used a tuple for `str.endswith()` to check all forbidden filenames in one call, improving speed and code clarity.
These changes preserve behavioral correctness while reducing runtime for large file lists or frequent function calls.
---
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📄 19% (0.19x) speedup for
filter_bad_extensionsinpr_agent/algo/language_handler.py⏱️ Runtime :
22.8 milliseconds→19.3 milliseconds(best of234runs)📝 Explanation and details
Explanation of Optimizations:
get_settings()calls eliminated: Avoided multiple calls toget_settings()within functions. Instead, retrieved settings once per function and reused, reducing overhead.+=on.extrabad extensions. Instead, computed the complete bad extensions set once and reused; this avoids each call modifying the list, prevents accidental side effects, and speeds up membership checks.setfor O(1) membership testing, reducing time complexity offilename.split('.')[-1] not in bad_extensionsfrom O(n) to O(1).str.endswith()to check all forbidden filenames in one call, improving speed and code clarity.These changes preserve behavioral correctness while reducing runtime for large file lists or frequent function calls.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-filter_bad_extensions-mgzh7vjnand push.