⚡️ Speed up function _get_attrs_config by 17% in PR #1860 (fix/attrs-init-instrumentation) - #1861
Conversation
The hot loop that checks decorators now extracts only the last two dotted-name segments (the namespace and decorator name) instead of building the full dotted string and splitting it, reducing profiler-reported time in `_get_attrs_config` from ~21 ms to ~9.7 ms (54% faster). Additionally, the boolean-literal check was inlined to eliminate ~6 ms of function-call overhead in `_bool_literal`. These changes together yield the 17% end-to-end runtime improvement with no semantic changes to behavior.
|
Claude finished @codeflash-ai[bot]'s task in 2m 58s —— View job PR Review Summary
Prek Checks✅ ✅ Code ReviewBug fixed: duplicate function definition
The optimization logic itself looks correct:
Duplicate DetectionNo duplicates detected. The pre-existing Test CoveragePer the PR description: 1266 generated regression tests passed at 100% coverage, plus 1 replay test. No existing unit tests were present for this function before the change. SummaryOne fix was committed: removed the duplicate |
⚡️ Codeflash found optimizations for this PR📄 126% (1.26x) speedup for
|
|
Closing: the js-esm-async-optimization E2E test is failing (error handling tests for processItemsSequential, a JavaScript function). This failure is unrelated to the _get_attrs_config Python optimization in this PR — the optimization only touches Python code and cannot affect JavaScript E2E test correctness. This appears to be a pre-existing failure in the test suite unrelated to this change. |
⚡️ This pull request contains optimizations for PR #1860
If you approve this dependent PR, these changes will be merged into the original PR branch
fix/attrs-init-instrumentation.📄 17% (0.17x) speedup for
_get_attrs_configincodeflash/languages/python/context/code_context_extractor.py⏱️ Runtime :
2.26 milliseconds→1.93 milliseconds(best of189runs)⚡️ 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 hot loop that checks decorators now extracts only the last two dotted-name segments (the namespace and decorator name) instead of building the full dotted string and splitting it, reducing profiler-reported time in
_get_attrs_configfrom ~21 ms to ~9.7 ms (54% faster). Additionally, the boolean-literal check was inlined to eliminate ~6 ms of function-call overhead in_bool_literal. These changes together yield the 17% end-to-end runtime improvement with no semantic changes to behavior.✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
⏪ Click to see Replay Tests
benchmarks/codeflash_replay_tests_46voh163/test_tests_benchmarks_test_benchmark_code_extract_code_context__replay_test_0.py::test_codeflash_languages_python_context_code_context_extractor__get_attrs_config_test_benchmark_extractTo edit these changes
git checkout codeflash/optimize-pr1860-2026-03-18T08.05.54and push.