-
Notifications
You must be signed in to change notification settings - Fork 26
⚡️ Speed up function _should_use_raw_project_class_context by 51% in PR #1838 (codeflash/optimize-pr1660-2026-03-16T19.13.06)
#1839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
misrasaurabh1
merged 2 commits into
codeflash/optimize-pr1660-2026-03-16T19.13.06
from
codeflash/optimize-pr1838-2026-03-16T19.35.10
Mar 16, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚡️Codeflash found 29% (0.29x) speedup for
_is_namedtuple_classincodeflash/languages/python/context/code_context_extractor.py⏱️ Runtime :
447 microseconds→347 microseconds(best of205runs)⚡️ This change will improve the performance of the following benchmarks:
🔻 This change will degrade the performance of the following benchmarks:
{benchmark_info_degraded}
📝 Explanation and details
The optimization inlines
_expr_matches_namedirectly into_is_namedtuple_class, eliminating 2,150 function calls that originally consumed 92.6% of total execution time. The hot loop now computes string concatenations (".NamedTuple") once outside the loop instead of on every iteration, and restructures the resolved-alias check to short-circuit earlier when no alias exists. Line profiler confirms per-iteration cost dropped from ~3,786 ns to ~1,943 ns. No test cases regress in correctness, and the 28% runtime improvement directly benefits callers like_collect_synthetic_constructor_type_namesand_build_synthetic_init_stubthat check hundreds of class definitions during AST traversal.✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
⏪ Click to see Replay Tests
benchmarks/codeflash_replay_tests_gwziwff1/test_tests_benchmarks_test_benchmark_code_extract_code_context__replay_test_0.py::test_codeflash_languages_python_context_code_context_extractor__is_namedtuple_class_test_benchmark_extractTo test or edit this optimization locally
git merge codeflash/optimize-pr1839-2026-03-16T19.49.25