⚡️ Speed up function detect_unused_helper_functions by 36% in PR #841 (fix-detect-unused-helper-functions)
#842
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 #841
If you approve this dependent PR, these changes will be merged into the original PR branch
fix-detect-unused-helper-functions.📄 36% (0.36x) speedup for
detect_unused_helper_functionsincodeflash/context/unused_definition_remover.py⏱️ Runtime :
37.2 milliseconds→27.5 milliseconds(best of5runs)📝 Explanation and details
Key optimizations made:
ast.walkin_analyze_imports_in_optimized_code, switching to a manual stack-based visitor that only scans body attributes, which is all that's needed for import analysis.set.isdisjointfor checking if helper names are unused, which is faster (short-circuits) than set intersection thenif not ....called_function_namesset to save attribute/method lookup costs.All comments, signatures, and behaviors are preserved and the code structure is unchanged unless a change was necessary for optimization.
✅ Correctness verification report:
⚙️ Existing Unit Tests and Runtime
test_unused_helper_revert.py::test_async_class_methodstest_unused_helper_revert.py::test_async_entrypoint_with_async_helperstest_unused_helper_revert.py::test_async_generators_and_coroutinestest_unused_helper_revert.py::test_class_method_calls_external_helper_functionstest_unused_helper_revert.py::test_class_method_entrypoint_with_helper_methodstest_unused_helper_revert.py::test_detect_unused_helper_functionstest_unused_helper_revert.py::test_detect_unused_in_multi_file_projecttest_unused_helper_revert.py::test_mixed_sync_and_async_helperstest_unused_helper_revert.py::test_module_dot_function_import_styletest_unused_helper_revert.py::test_multi_file_import_stylestest_unused_helper_revert.py::test_nested_class_method_optimizationtest_unused_helper_revert.py::test_no_unused_helpers_no_reverttest_unused_helper_revert.py::test_recursive_helper_function_not_detected_as_unusedtest_unused_helper_revert.py::test_static_method_and_class_methodtest_unused_helper_revert.py::test_sync_entrypoint_with_async_helpers🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-pr841-2025-10-21T21.27.16and push.